【发布时间】:2014-07-03 12:35:28
【问题描述】:
我试图让我的背景变得固定,即使浏览器变小并且内容运行到底部。
我现在面临的问题是,我的背景尺寸不是标准尺寸1366*768,我现在的尺寸是1366*1000,所以我的网站可以滚动了。
当浏览器变小,内容变窄时,我的背景无法固定内容的下部,底部会出现白色区域,有什么办法解决吗?
谢谢
CSS:
body {
background-attachment: scroll;
background-image: url(img/homebg.png);
background-repeat: no-repeat;
background-position: center top;
-webkit-background-size: cover;
-moz-background-size: 100% 100%, auto;
-o-background-size: 100% 100%, auto;
background-size: 100% 100%, auto;
height: 100%;
background-size: cover;
margin: 0;
padding: 0;
color: #000;
font-family: KaiTi, "Century Gothic";
font-size: 100%;
line-height: 1.4;
}
html {
height: 100%;
padding: 0;
margin: 0;
}
.container {
width: 1200px;
margin: 0 auto;
}
更新了(我说的对吗?)
body {
background: url(img/homebg.png) no-repeat top left scroll;
background-size: auto auto;
margin: 0;
padding: 0;
color: #000;
font-family: KaiTi, "Century Gothic";
font-size: 100%;
line-height: 1.4;
}
html {
height:100%;
padding:0;
margin:0;
}
</style>
</head>
<body>
<script>
function resizeIt() {
$("body").css("background-size", $(document).width() + "px " + $(document).height() +"px");
}
$(window).resize(function () {
resizeIt();
});
resizeIt();
</script>
</body>
【问题讨论】:
-
你想让你的图像拉伸到最底部吗?还是……?
-
如果我理解正确,您希望背景图像覆盖整个页面,而不管其大小。如果是这种情况,那么您可能需要检查:srobbin.com/jquery-plugins/backstretch
-
@shodaburp 是的,这就是我想要的。但是我的背景图片大小是1366*1000,我的网页大小应该是1366*1000,这样就可以滚动了。但是当我减小浏览器的大小时,我的内容会变长,但我的背景图片无法修复,因此底部会有空白,有什么方法可以解决?
-
@Thauwa 没有拉伸到最底部,我只希望我的图像覆盖整个页面,而不管浏览器大小如何,我希望我的 bg 图像保持静态,即使内容缩小。我希望我的背景图像变成静态的 1366*1100,只是我的内容能够滚动。因为我的bg图片不是标准尺寸,请问有什么方法可以解决吗?
标签: html css background height width