Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
324 views
in Technique[技术] by (71.8m points)

javascript - How can I prevent my fixed div from overlapping my other divs

I'm making a website for my world history class and I am attempting to make a heading for the website. Unfortunately, the heading overlaps the first paragraph. Is there any way I can fix this without changing the position? I need the position to be fixed. This is the html for the header:

<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>

This is the 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;
}

Thank you for the help.

question from:https://stackoverflow.com/questions/65941683/how-can-i-prevent-my-fixed-div-from-overlapping-my-other-divs

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you have to keep the position fixed for some reason you can give the menu a fixed height and add that value as a top margin to the paragraph.

#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, and top properties. The header will stay at the top and the paragraph will show.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...