我该如何达到那种效果?
要实现完整的水平和垂直,请尝试以下内容:
background-image: url(image.jpg);
background-repeat:no-repeat;
background-position:center center;
background-attachment:fixed;
-o-background-size: 100% 100%, auto;
-moz-background-size: 100% 100%, auto;
-webkit-background-size: 100% 100%, auto;
background-size: 100% 100%, auto;
你的问题很可能源于body标签的静态定位,因此其子元素的高度相对于html标签。
尝试添加以下内容:
body{
position:relative;
}
它将使body的子元素使用文档的大小而不是浏览器视口。
这是一个它工作的例子:http://jsfiddle.net/cP9hu/
z-index
,因为IE7会使它们混乱? - alex那听起来像是需要通过 JavaScript 处理的事情。个人建议使用 jQuery,类似这样:
$(document).ready(function() { //Runs at page load
$(".ID_OF_IMAGE").each(function() { //calls the anon function for the id tag specified
/*sets the height to the max of three methods of height measurement
diff browsers detect doc height differently.*/
this.height = Math.max(
//gets the larger between doc height and body height
Math.max(document.body.clientHeight, document.documentElement.clientHeight),
Math.max(document.body.offsetHeight, document.documentElement.offsetHeight),
Math.max(document.body.scrollHeight, document.documentElement.scrollHeight))
});
});
或者你可以将图片设置为div或body的背景,并使用repeat-y css属性。
body { //also works for div's
background-image:url('image.jpg');
background-repeat:repeat-y;
}
-SB