gpt4 book ai didi

css - 限制背景滑过屏幕的最左边缘

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

对不起,我不知道如何更清楚地表达这个问题,但我的网页 background-position 当前设置为 center。当我调整窗口大小时,它停留在最中心,当窗口小于背景图像时,图像保持居中,因此左右边缘都被切断。我遇到的问题是,当我使用 margin:auto; 时,我的 div 内容框将留在中心,但是当窗口的大小调整为小于 的宽度时width:700px;,框的最左边缘保持在可见范围内,而最右边缘隐藏在窗框之外。我真的很难解释,如果我不清楚,我很抱歉。我对网络开发很陌生。以下是屏幕截图示例:
http://puu.sh/7jnNV.jpg : 好的!一切都居中对齐
http://puu.sh/7jnPO.jpg : 坏的!背景图像仍然居中于窗口的宽度,但 div 框停在最左边,然后跑到另一边:
http://puu.sh/7jnSN.jpg : 由于宽度是固定的,它会偏离背景的一侧,因为它偏离了背景的中心。

这是到目前为止的网页代码:

<head>
<style>
html, body {
min-height: 100%
}
body {
background-color: #ffffff;
background-image: url(banner.png), url(footer.png), url(filler.png);
background-position: center top, center bottom, center center;
background-repeat: no-repeat, no-repeat, repeat-y;
}
</style>
</head>

<body>
<style>
div.content
{
width:700px;
padding:10px;
border:2px solid #004688;
margin:auto;
margin-top:400px;
margin-bottom: 135px;
}
</style>
<div class="content">test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test</div>
</body>

所以我认为最简单的解决方法是阻止背景滑过屏幕的最左侧边缘,这样一切都相对于彼此居中。但我不知道该怎么做,谷歌搜索也无济于事,因为我不知道 wtf 我什至在谈论大声笑;c

最佳答案

在容器 div 中应用背景。

容器div的高度和宽度将与背景相同。

现在使用 CSS 将容器 div 水平和垂直居中。

关于css - 限制背景滑过屏幕的最左边缘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22187080/

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