gpt4 book ai didi

html - 在减小浏览器大小时,使背景填充 100% 浏览器的任何编码

转载 作者:行者123 更新时间:2023-11-28 10:07:27 26 4
gpt4 key购买 nike

我试图让我的背景变得固定,即使浏览器变小并且内容运行到底部也是如此。

我现在面临的问题是,我的背景尺寸不是标准尺寸 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>

最佳答案

您可以尝试以下方法:

CSS

body {
background: url(yourImage.jpg) no-repeat top left scroll;
background-size: auto auto;
color: #000;
font-family: KaiTi, "Century Gothic";
font-size: 100%;
line-height: 1.4;
}
.container {
margin: 0 auto;
}

jQuery

function resizeIt() {
$("body").css("background-size", $(document).width() + "px " + $(document).height() + "px");
}
$(window).resize(function () {
resizeIt();
});
resizeIt();

演示: http://jsfiddle.net/thauwa/P7GM4/

关于html - 在减小浏览器大小时,使背景填充 100% 浏览器的任何编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24505883/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com