gpt4 book ai didi

html - 缩放时未遵守 CSS 100%

转载 作者:太空宇宙 更新时间:2023-11-04 15:30:36 24 4
gpt4 key购买 nike

我想在整个屏幕上有一个宽度为 100% 的黄色矩形 #box-over。在 Google Chrome 上的默认缩放级别(我没有尝试过所有浏览器)它工作正常,除非我放大超过 300% 左右然后黄色框不再是屏幕的 100% 它被剪裁底部出现水平滚动条。我似乎无法弄清楚如何解决此问题。

JSFIDDLE http://jsfiddle.net/VySGL/1/

屏幕截图 enter image description here

来源

        <style type="text/css">
body {
padding: 0;
margin: 0;
background-color: black;
}

#box {
width: 100%;
position: relative;
}

#box #box-over {
z-index: 1;
width: 100%;
height: 50px;
background-color: yellow;
position: absolute;
top:10px;
opacity:0.8;

}

#box #box-over .box-column {
width: 900px;
margin: 0 auto;
zoom: 1;
position: relative;
height: 50px;
}
</style>

</head>
<body>

<div id="box">
<div id="box-over">
<div class="box-column">
</div>
</div>
</div>

</body>
</html>

最佳答案

使用 100% 宽度的替代方法是像这样在 CSS 中将 left 和 right 设置为 0...

参见 JSFiddle

#box #box-over {
z-index: 1;
left: 0;
right: 0;
height: 50px;
background-color: yellow;
position: absolute;
top:10px;
opacity:0.8;

}

#box #box-over .box-column {
left: 0;
right: 0;
margin: 0 auto;
zoom: 1;
position: absolute;
height: 50px;
}

使用 left 和 right 属性可确保您永远不会超过 100% 宽度,即使您添加了填充(参见 this JSFiddle)。

例如,当您向 div 添加内边距时,它将 100% 加上内边距。参见 JSFiddle

关于html - 缩放时未遵守 CSS 100%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14470019/

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