I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large background images, the whole thing becomes visible.
My current screen resolution is 1280 x 1024.
If I do the following:
then in FF, the following happens:
Update: IE does it correctly. Google Chrome has the same problem.
It is as if Firefox first renders the background image at 100% width, centers it, and then notices that the body needs to be stretched to 1400px.
Is this normal Firefox behaviour? Any ideas what I can do?
Posting a link would be a bit cumbersome as it's all in a closed development environment but if all else fails, I will put something together to look at.
The CSS:
body
{
background-image: url(http://www.domain.com....image.jpg);
background-repeat: no-repeat;
background-position: center center;
min-width: 1400px;
height: 100%;
}
You're being bitten by a quirk of the CSS specification: thanks to section 14.2, any background image you apply to the body
element becomes the background to html
instead. (This was intended so that authors could carry on using background on the body tag where they expected it to be from pre-CSS browsers.)
In IE, html
represents the whole document canvas and expands to fit the enlarged body width. In other browsers it acts like any other display: block
element and keeps the viewport width regardless of what you put in it. The other browsers are arguably more correct here, but the CSS spec is not terribly clear on the topic, and the upshot is that the results in IE more closely represent the wording of 14.2 about the canvas. Either way, it's not really specified reliable behaviour.
You can get consistent results across browsers by setting the width and background on html
instead of body
. (Remember to use Standards Mode in IE.)
But a 1400px
fixed-width document? Sounds like a really bad idea.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With