gpt4 book ai didi

html - DIV 被之前的 DIV 覆盖

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

我有以下简单的 html

<body>
<div style="position:fixed;width:100%;top:0;left:0;height:45px; background-color:silver">
top
</div>

<div style="width:600px;background-color:yellow;margin:auto">
bottom
</div>
</body>

当我在浏览器中运行页面时,银色的 DIV 覆盖了黄色的。我想看看黄色的,就在银色的下面。我应该如何更改它?

最佳答案

那是因为你让它给出了一个固定的位置。这将 silver div 置于文档流之外。

给你的 body 添加一个填充,这将使你的黄色 div 再次出现。

<body style="padding-top: 45px;">
<div style="position:fixed;width:100%;top:0;left:0;height:45px; background-color:silver">
top
</div>

<div style="width:600px;background-color:yellow;margin:auto">
bottom
</div>
</body>

关于html - DIV 被之前的 DIV 覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40291405/

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