gpt4 book ai didi

html - 为什么不显示固定 div 的 4px 边距?

转载 作者:太空宇宙 更新时间:2023-11-04 10:03:55 26 4
gpt4 key购买 nike

我有一个简单的固定位置<div>其中有 100% width .它有 4px margin 周围。但是,它不显示右侧的边距。为什么?

代码如下:

<html>

<body>
<div style="position:fixed;height:50px;width:100%;margin:4px;background-color:black;">
</div>
</body>

</html>

最佳答案

它的右边确实有一个边距,但是你看不到它,因为它被推到了屏幕的边缘。这是因为宽度是 100%,就是 body 的宽度。解决它的最佳方法是使用 topleftright

div {
position: fixed;
height: 50px;
left: 4px;
right: 4px;
top: 4px;
background-color: black;
}

body {
margin: 0;
}
<div></div>

这样你仍然有边距,只有topleftright的形式。

关于html - 为什么不显示固定 div 的 4px 边距?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38160367/

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