Can anyone help me fix my CSS so the images that you will see in the link below appear directly below each other? I am relating to the images that are currently moving towards the right where the comments are…
Hi,
Yes, a quick fix would be to add clear:left to your floated images. You will probably need to remove the 20px bottom margin from them though and rethink your code a little. Things start getting out of sync with that bottom margin on the image.
You might try setting up a ruleset for the p tags in that div and set the margins there. Or wrap each section (image and text) in a list item for even more control.
[B].comments img[/B]{
float:left;
[COLOR=Blue]clear:left;[/COLOR]
margin-right:10px;
[COLOR=Red]/*margin-bottom:20px; margins moved to p tag*/[/COLOR]
}
[COLOR=Black][B].comments p[/B][/COLOR]{
[COLOR=Blue] margin:10px 0; [/COLOR]
background:yellow;/*testing only*/
}
everything thats inside the p elements put a wrapper around it give it a width and float it left. This will cause the date name read more link to be aligned next to the images.
Something like the examples below is what I was referring to. They use a <dl> but it could be done with a standard ul with p tags and spans in the <li>.
Well, something as simple as this unordered list would serve as a starting point for wrapping your image and text up in a list item. From there you can add some more text formatting elements such as spans.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Image and Text within Lists Items</title>
<style type="text/css">
#blog {
width:400px;
margin:20px auto;
padding:0 5px 5px;
list-style-type:none;
background:#777;
overflow:hidden;/*contain floated li*/
}
#blog li {
float:left;/*contain floated image*/
width:100%;/*prevent float from shrinkwrapping*/
margin:5px 0 0 0;
padding:5px 0;
background:#EEF;
}
#blog li p {
color:#000;
margin:0 0 0 85px;
padding:0 2px;
}
#blog li img{
float:left;
margin:0 5px;
}
</style>
</head>
<body>
<ul id="blog">
<li><img src="http://www.css-lab.com/demos/vertical-center/images/image-75.gif" alt="test image">
<p>Lorem ipsum dolor sit amet consectetuer dui porta magnis Morbi egestas. Magna felis commodo
pede tellus condimentum pede leo Nulla vel mauris. Purus porttitor In Maecenas at et felis
adipiscing vitae Sed eleifend.</p>
</li>
<li><img src="http://www.css-lab.com/demos/vertical-center/images/image-75.gif" alt="test image">
<p>Lorem ipsum dolor sit amet consectetuer dui porta magnis Morbi egestas.</p>
</li>
<li><img src="http://www.css-lab.com/demos/vertical-center/images/image-75.gif" alt="test image">
<p>Lorem ipsum dolor sit amet consectetuer dui porta magnis Morbi egestas. Magna felis commodo
pede tellus condimentum pede leo Nulla vel mauris. Purus porttitor In Maecenas at et felis
adipiscing vitae Sed eleifend.</p>
</li>
</ul>
</body>
</html>