Forum Moderators: not2easy

Message Too Old, No Replies

max-width and background color?

         

keyplyr

7:51 am on May 15, 2005 (gmt 0)

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



In FireFox, I was surprised to see the background color fill the screen even though the webpage stopped at the desired width. Is it possible to have the bg color stop with the page content? And how would I center all this? Thanks.

html, body {
background-color:#f0f8ff;
color:#000;
border:1px solid #699;
max-width:1020px;
margin:0;
padding:0;
}

tedster

4:42 pm on May 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's probably because you applied background-color to the html element as well as the body - right?

Robin_reala

5:01 pm on May 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's a hazy area in my experience, but the <html> element is usually (always?) the entire width of the viewport in browsers.

keyplyr

5:20 pm on May 15, 2005 (gmt 0)

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



Thanks, I've been trying to remember why I included html in the first place. There must have been a significant reason (LOL.)

keyplyr

5:32 pm on May 15, 2005 (gmt 0)

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



Nope, removing the html element didn't change anything. The background-color still fills the screen (tested in Firefox only.)

And BTW, I'm sure there was a good reason for reducing the time an owner may edit his post, but...?

iamlost

6:52 pm on May 15, 2005 (gmt 0)

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



CSS 2.0:

[w3.org ]

For HTML documents, however, we recommend that authors specify the background for the BODY element rather than the HTML element. User agents should observe the following precedence rules to fill in the background: if the value of the 'background' property for the HTML element is different from 'transparent' then use it, else use the value of the 'background' property for the BODY element. If the resulting value is 'transparent', the rendering is undefined.

CSS 2.1 is identical except that it adds the following sentence:

[w3.org ]

This does not apply to XHTML documents.

So FF appears to be following the specs: The default is background-color: transparent;. If you specify a colour for <body> but not <html> use the <body> colour value for both. This has the intewresting result you mention when <html> and <body> dimensions differ. If both <html> and <body> are left default most browsers show the "undefined" background as white (but it is not specified that it be so).

The solution is to colour each separately:


html {width: 100%; height: 100%; background-color: #f0f;
}
body {max-width: 600px; /* for test on smaller screen */ height: 100%; /* to display for test purposes */ padding: 0; margin: 0 auto; border: 1px solid #699; background-color: #f0f8ff;
}

keyplyr

8:43 pm on May 15, 2005 (gmt 0)

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



Thanks iamlost, I knew how to maker the HTML white, just was confused why it didn't do it by default. Didn't know transparent was the default. Thought it would display white like everything else. Guess all defaults are transparent, just don't notice it unless the main element is colored.