【发布时间】:2015-04-19 10:06:56
【问题描述】:
在我的网络中,我有一个固定的导航栏,在它下面我有一些其他的 div - 导航栏链接连接到这些链接。 问题是当我单击某个链接时,固定导航栏覆盖了 div 的开头。我想要做的是导航栏将位于 div 的开头,因此它不会覆盖开头。 这是结果的link。
这是我的 html 代码:
<body>
<div id="header">
<div id="nav_bar">
<ul>
<li><a href="#">בית</a></li>
<li><a href="#about_us">מי אנחנו</a></li>
<li><a href="#our_services">מוצרים</a></li>
<li><a href="#connect_us">צרו קשר</a></li>
<li><img src="1.png"></img></li>
</ul>
</div>
</div>
<div id="main_pics" class="container">
<!-- photos here -->
<div id="main_photo1" class="phocont first">
</div>
<div id="main_photo2" class="phocont">
</div>
<div id="main_photo3" class="phocont">
</div>
<div id="main_photo4" class="phocont">
</div>
<div id="main_photo5" class="phocont">
</div>
</div>
<div id="about_us" class="container">
<h1>עץ כנעני - כשעיצוב ואיכות נפגשים</h1>
<p> וייצור המוצר.</p>
<p>א.</p>
</div>
<div id="our_services" class="container">
<h1>המוצרים שלנו</h1>
</div>
<div id="connect_us" class="container">
<h1>תאמו איתנו פגישה עוד היום</h1>
</div>
<div id="down_nav_bar" class="container">
</div>
<div id="credit" class="container">
</div>
</body>
这是我的css代码:
body{
background-color: white;
margin: 0px;
padding: 0px;
}
#nav_bar{
background: rgba(255,255,255,0.9);
height: 55px;
position: fixed;
width: 100%;
top: 0;
left: -2px;
z-index: 2;
}
#nav_bar ul{
padding: 0px;
text-align: center;
direction: rtl;
}
#nav_bar ul li {
display: inline-block;
padding: 0 10px;
color: gray;
float: inherit;
font-family: "alefregular";
font-size: 23px;
}
#nav_bar ul li a{
color: inherit;
text-decoration: none;
}
#nav_bar ul li a:hover{
color:#a51212;
}
#nav_bar img{
height:18px;
position:absolute;
padding-right:20px;
top:25px;
z-index:-1px;
}
#about_us{
text-align: center;
/*height: 250px;*/
height: 100%;
font-family:"open_sans_hebrewregular", "alefregular",arial,"Times New Roman";
color:gray;
}
#about_us p{
width: 55%;
margin: auto;
text-align: center;
direction: rtl;
padding-bottom: 10px;
line-height: 30px;
}
#our_services{
/*height: 450px;*/
text-align: center;
font-family:"open_sans_hebrewregular", "alefregular",arial,"Times New Roman";
color: black;
background-color: rgb(224,224,224);
}
【问题讨论】:
-
问题是因为导航有固定的位置。如果您在所有内容容器中添加上边距,它将解决您的问题。
-
但是内容开始向下 55px。这不是我想要的......
-
您可能想使用 jquery 并设置 .scroll() 选项
-
APRULE,请查看我修改后的答案,它更适合您的需求。 @gerdi,好建议!
-
它仍然对我不起作用。
标签: javascript html css