繁体   English   中英

如何防止我的固定 div 与其他 div 重叠

[英]How can I prevent my fixed div from overlapping my other divs

我正在为我的世界历史 class 制作一个网站,并且我正在尝试为该网站制作一个标题。 不幸的是,标题与第一段重叠。 有什么办法可以在不更改 position 的情况下解决这个问题? 我需要修复 position。 这是 header 的 html:

<div id="menu">
<a href="#about">About</a>
<a href="#donatello">Donatello</a>
<a href="#michelangelo">Michelangelo</a>
<a href="">Martin Luther</a>
<a href="">Henry VIII</a>
<a href="">Mary Wollstonecraft</a>
<a href="">Francis Bacon</a>
<a href="">Isaac Newton</a>
<a href="">Galileo Galilei</a>
<a href="">Marquis de Lafayette</a>
</div>

这是 css:

#menu{
padding:30px;
background:#000;
border:5px solid #000000;
border-radius:0px;
position:fixed;
z-index:1;
right:0px;
left:0px;
top:0px;
text-align:center;
}

感谢您的帮助。

如果由于某种原因您必须保持 position 固定,您可以给菜单一个固定的高度并将该值作为上边距添加到段落。

#menu{
...
max-height: 100px;
}

p{
margin-top: 100px;
}

If you don't need position: fixed (because technically you don't if you just want to keep your header up top) you can use position: sticky as s.kuznetsov mentioned in comments or you can just take out position, right, left 和 top 属性。 header 将停留在顶部并显示段落。

#menu{
padding:30px;
background:#000;
border:5px solid #000000;
border-radius:0px;
z-index:1;
text-align:center;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM