Forum Moderators: open

Message Too Old, No Replies

Background images and DIV placement

Different margins in different browsers

         

ChrisBolton

7:01 pm on Aug 24, 2006 (gmt 0)

10+ Year Member



Hi all,

I seem to be having a problem with a new site I am working on.

I have a background image in the <body> tag which spans the width of the page, whatever the screen size. The image is designed to line up exactly with the navigation inside a <div> tag.

In IE, everything looks right, but in Opera and Firefox the div seems to be sitting 20px or so lower. I am assuming that margins have been added automatically in these browsers.

Is there any way around this. Maybe using conditional statements in the CSS to use a different background image depending on the browser detected.

Any help would be greatly appreciated.

Best Regards.
Chris.

Fotiman

8:18 pm on Aug 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Why not simply remove the margins/padding?

body
{
margin: 0;
padding: 0;
background: ... <-- Your image here
}

tedster

8:40 pm on Aug 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What's the DTD? Since it looks "right" in the non-standard browser and looks "wrong" in the more standards-compliant browsers, I think your layout may be depending on non-standard handling of some element.

ChrisBolton

11:37 am on Aug 25, 2006 (gmt 0)

10+ Year Member



Cheers guys,

I solved the problem, it was not a border or a margin problem. It was something else that I have not seen before. In the very first div I had to smaller floating divs, one to the left and one to the right. The left div was sitting at the top of the page but the right one seemed to be getting pushed down by the first one, I decreased the width by 10px and now it looks right in every browser.

I imagine that it was adding extra padding somewhere and the width of the two floated divs was too much for the container div.

Thanks guys.

Regards, Chris.