gpt4 book ai didi

html - 居中页面宽度背景图像正在拉伸(stretch)页面

转载 作者:太空宇宙 更新时间:2023-11-03 19:31:03 24 4
gpt4 key购买 nike

几个小时以来,我一直在尝试解决这个问题,而且我已经在整个互联网上进行了搜索,但没有成功。

我正在尝试将此背景图像置于页面中央;然而如图所示here通过使用此方法,它会拉伸(stretch)页面的宽度,这意味着您可以滚动超过页面的宽度。

这是我的代码:

HTML:

<!DOCTYPE html>
<html>
<body>
<div class="container">
<div class="bground">d</div>
</div>
</body>
</html>

CSS:

div.container {
position: absolute;
width: 100%;
height: 100%;
left: 50%;
}

div.bground {
position: relative;
width: 100%;
height: 100%;
left: -50%;
background: url('http://cdn.bleedingcool.net/wpcontent/uploads/2015/04/skyrim.jpg') no-repeat center center scroll;
}

最佳答案

您将容器 div 向右移动了 50%,这就是为什么您得到水平滚动条,不是超出图像而是超出 div 定位。试试这个 CSS:

div.container {
position: absolute;
width: 100%;
height: 100%;
left: 0;
}
div.bground {
position: relative;
width: 100%;
height: 100%;
left: 0;
background: url('http://cdn.bleedingcool.net/wp-content/uploads/2015/04/skyrim.jpg') no-repeat center center scroll;
}

关于html - 居中页面宽度背景图像正在拉伸(stretch)页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30075964/

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