Forum Moderators: not2easy

Message Too Old, No Replies

centered background image

Opera problem - Fine is Firefox, IE, NN

         

D_Blackwell

7:07 am on Aug 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I want an image centered on the screen. Opera centers horizontally, but moves it UP 50% of the image height.?
<body style="margin: 0; padding: 0; background: #000 url(image.jpg) 50% no-repeat;">

SuzyUK

1:28 pm on Aug 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



interesting..

it's something to do with the height of the body element, as in the <body> element is not automatically 100% of the viewport. ( <html> is the root element in strict mode )

So I added a background color to the <html> element to see where the two elements where in relation to each other.. that triggered the described Opera behaviour in IE and totally blanked out the <body> element in FF/Opera (proving the body element has no height, until content is added of course..)

IE gives every empty element a minimum height (approx 16px), so that's why it shows a bit in there.. LOL
then I expected to have to add 100% heights to html and body, so the body would inherit the height, which worked... but would cut off after the page got longer than 100%..

but it also worked by only adding a height to the HTML element when the <html> background was removed.. weird.. it's like if there's no background on HTML then the <body> takes over height an' all, otherwise the <html> background trumps it?

can't get my head around it all, but min-height seems to be the answer, the CSS below seems to work best crossbrowser, and I tested with lots of content to make sure the body did not cut off.. IE must be doing it's own thing again...


html {
margin: 0; padding: 0;
/* background: #000; */
min-height: 100%;
}

body {
margin: 0; padding: 0;
background: #ccc url(hello.gif) no-repeat 50% 50%;
}


uncomment the html background for a different story ;)

what am I not seeing?

Suzy

D_Blackwell

4:29 pm on Aug 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Wow. You got your head around a whole lot more of it than I did. Esoecially appreciate the explanation of the logical progression of your approach. It's like sitting there with you. I'm still a bit mystified, but at least feel like I've got a firner footing.