从导航栏中删除空格

时间:2018-02-01 11:40:02

标签: html css html-lists whitespace nav

这是我的代码(我是html中的总菜单)这段代码在导航的顶部和左侧给了我空白区域......你们有什么想法我做错了吗?

socket.setsockopt(zmq.SUBSCRIBE, "")

添加了html

2 个答案:

答案 0 :(得分:1)

这是CSS。添加此

body{
   padding: 0;
   margin: 0;
 }



body{
   padding: 0;
   margin: 0;
   
   background-color: #e8e4e5;
 }
 div.nav {
  background-color: black;
  color: white;
  font-size: 20px;
  font-weight: bold;
  position: fixed;
  width: 100%;
  text-align: center;
}
ul {

}
li {
  display: inline-block;
  list-style: none;
}
li a {
  padding: 15px;
  color: white;
}

<div class="nav">
  <ul>
    <li><a href="index.html">Home</a></li>
    <li><a href="watisdb.html">Wat is D&B</a></li>
    <li><a href="dbnederland.html">D&B in Nederland</a></li>
  </ul>
</div>
&#13;
&#13;
&#13;

但你可以设置导航div位置固定:当你滚动内容时它会有所帮助,但导航div总是在顶部。

&#13;
&#13;
 body{
   padding: 0;
   margin: 0;
 }
 .content{
   margin-top: 60px;
   height: 150vh;
   background-color: #d2d29d;
 }
 div.nav {
  position: fixed;
  height: 60px;
  background-color: black;
  color: white;
  font-size: 20px;
  font-weight: bold;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  text-align: center;
}
ul {

}
li {
  display: inline-block;
  list-style: none;
}
li a {
  padding: 15px;
  color: white;
}
&#13;
<div class="nav">
  <ul>
    <li><a href="index.html">Home</a></li>
    <li><a href="watisdb.html">Wat is D&B</a></li>
    <li><a href="dbnederland.html">D&B in Nederland</a></li>
  </ul>
</div>
<div class="content">
  Some text
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

由于您正在使用position:fixed;,因此您可以将css更改为以下内容,这会强制导航栏位于页面的左上角

div.nav {
    background-color: black;
    color: white;
    font-size: 20px;
    font-weight: bold;
    position: fixed;
    top:0; //<================= Add this
    left:0; //<================= And add this
    width: 100%;
    text-align: center;
}

当然,还有更多方法。上面的CSS会导致你的空格被移除

&#13;
&#13;
    div.nav {
  background-color: black;
  color: white;
  font-size: 20px;
  font-weight: bold;
  position: fixed;
  top:0; //<================= Add this
  left:0; //<================= And add this
  width: 100%;
  text-align: center;
}
ul {

}
li {
  display: inline-block;
  list-style: none;
}
li a {
  padding: 15px;
  color: white;
}
&#13;
<div class="nav">
  <ul>
    <li><a href="index.html">Home</a></li>
    <li><a href="watisdb.html">Wat is D&B</a></li>
    <li><a href="dbnederland.html">D&B in Nederland</a></li>
  </ul>
</div>
&#13;
&#13;
&#13;

希望这有帮助!