If I try to set a background image for <html>
to be centered and top and for <body>
to be centered and bottom it doesn't work and only <html>
background is shown.
Is this in every browser or not?
If I try to set a background image for <html>
to be centered and top and for <body>
to be centered and bottom it doesn't work and only <html>
background is shown.
Is this in every browser or not?
You can use CSS3 to achieve this using multiple backgrounds. Something like:
body {
background-image: url(bg1.png), url(bg2.png);
background-position: center top, center bottom;
}
If not, make sure your body
and html
are 100% height, or at least have a min-height
of 100%.
The <html>
tag is the document root and wasn't really intended to be visible or have CSS properties applied to. CSS spec 2.1 does define the <html>
to have a box-model, but I still wouldn't rely on it.
You can either set multiple backgrounds with CSS3, or create an additional (absolute or fixed) <div>
like so:
HTML
<body>
<div id="container">
<!-- your usual content -->
</div>
<div id="bg"></div>
</body>
CSS
body { background-image: url(...); }
#bg {
background-image: url(...);
float: left; /* body overflow fix */
left: 0;
position: absolute;
top: 0;
height: 100px; /* height of your background */
width: 100%;
z-index: -1000;
}
Use different image for both and add height:100%
html{
background:url(https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTNxe5UjGfVsd1EpdEtrrlGDhjEO2VMFoIY9SGRCuBd4qAr9XhcCQ) top center no-repeat;
height:100%
}
body{
background:url(https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRqQ6g5bisPWccunUGGItC09wa1kgcc5X-rEEGGdEoWEwqUCnuZ) bottom center no-repeat;
height:100%
}