tags:

views:

146

answers:

3

Hey guys, I have the following div layout:

Everything is fine when I put normal txt elements in both the blue and the orange div. However, when I place an image in the orange div (which is 31px), the elements in the blue div get pushed down by about half the height of the blue div.

(additional info, when hovering over the html for the orange div in firebug, it seems like only half of the image is contained within it, even though to the naked eye it appears fine).

Would appreciate any help, I'm still a bit rusty on the box model. Thanks.

A: 

I'm not so good with CSS boxes, but could adding: display:inline; to the image style fix the porblem? And/Or adding margin:0px;
Oh and is the brwoser rendering in Quirks mode, since not making it render in Quirks mode could fix some problems too.

Edit
By quirks mode I mean, does your page has a DOCTYPE declaration similar to the one below (although you should off course use the corrext DOCTYPE)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;

more about DOCTYPES here: http://htmlhelp.com/tools/validator/doctype.html

Pim Jager
unfortunately not. thanks for suggestion though. And browser is firefox default settings.
+2  A: 

Try floating the two interal divs.

float:left;

adam
Don't forget to clear them both, too. :)
Zack Mulgrew
Why should they be cleared?
Tomalak
+2  A: 

You might want to try floating the image to the left of the text. This way the text will sit next to the image without the need for positioning. For example:

<style>
div {
position: absolute;
border: 1px solid blue;
}
div img {
height: 31px;
width: 50px;
float: left;
}
</style>

<div>
    <img src="myImage.gif">
    <p>Lorem ipsum dolor sit amet...</p>
</div>

Adjust the layout by giving your container div some padding and/or the image a margin and you should be able to get exactly the look you're after. Good luck!

Ola Tuvesson
ah great! thank you very much.