I'm having this problem, same as ever, but never try to find the right solution
code:
<div id="ListOfTextAndPhotos">
<div style="border-bottom: solid 1px silver;">
<img src="photo.jpg" style="float: left">
Some text about the photo
</div>
<div style="border-bottom: solid 1px silver;">
<img src="photo2.jpg" style="float: left">
Some text about the photo2
</div>
<div style="border-bottom: solid 1px silver;">
<img src="photo3.jpg" style="float: left">
Some text about the photo3
</div>
</div>
Question: How do I to keep the photo inside the DIV? with the separator line under the photo
The CSS float property controls the positioning and formatting of content on the page. Its most common use is to wrap text around images. However, you can use the float property to wrap any inline elements around a defined HTML element, including lists, paragraphs, divs, spans, tables, iframes, and blockquotes.
Because of this ability, floats have been used in web layouts time and time again. Since they weren't considered for full web layouts when they were built, using floats as such usually leads to layouts breaking unexpectedly, especially when it comes to responsive design, and that can get quite frustrating.
The more traditional way (other than clearing) is to set the overflow property of the containing div to hidden.
<div style="border-bottom: solid 1px silver; overflow: hidden;">
<img src="photo3.jpg" style="float: left">
<div>Some text about the photo3</div>
</div>
Sometimes, IE6 does not honor the setting and you have to resort to the cLFlaVA hack.
Floating an element takes it out of the flow of the document, therefore it will not take up space in the general flow when rendering on the screen. There are other ways of handling this, but here's a hack:
<div id="ListOfTextAndPhotos">
<div style="border-bottom: solid 1px silver;">
<img src="photo.jpg" style="float: left">
<div style="clear:both;">Some text about the photo</div>
</div>
<div style="border-bottom: solid 1px silver;">
<img src="photo2.jpg" style="float: left">
<div style="clear:both;">Some text about the photo2</div>
</div>
<div style="border-bottom: solid 1px silver;">
<img src="photo3.jpg" style="float: left">
<div style="clear:both;">Some text about the photo3</div>
</div>
</div>
A quick and dirty way to do it would be to float the containing div as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With