Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css: float image to the left - problem

i'm trying to do something like:

--------------------------------------------
| --------- text text text text text text  |
| | image | text text text text text text  |
| |       | text text text text text text  |
| |       | text text text text text text  |
| --------- text text text text text text  |
| text text text text text text text text  |
| text text text text text text text text  |
--------------------------------------------

the markup should be right:

<div>
    <img src='myimage.jpg' style='float:left;'>
    tex text text ..
</div>

the problem is - if there's only a few text, the image will "float out" from the container div, which looks like this:

--------------------------------------------
| --------- text text text text text text  |
| | image | text text text text text text  |
|_|       |________________________________|
  |       |
  ---------

any ideas to fix this? the only solution to me seems setting the div container's min-height. thx

like image 850
Fuxi Avatar asked Aug 09 '10 11:08

Fuxi


3 Answers

div {
    overflow: hidden;  /* except IE6 */
    display: inline-block; /* IE6 */
}
div {
    display: block; /* IE6 */
}
like image 142
Ionuț G. Stan Avatar answered Nov 14 '22 08:11

Ionuț G. Stan


add an empty element at the end of the div element with style="clear:both;, just like this:

<div>
    <img src='myimage.jpg' style='float:left;'>
    tex text text ..
    <div style="clear:both;"></div>
</div>
like image 45
jigfox Avatar answered Nov 14 '22 10:11

jigfox


<div style="overflow:auto"> </div>

like image 1
Deepak Avatar answered Nov 14 '22 10:11

Deepak