如何删除导航栏上方的空白区域?

时间:2017-10-25 15:42:24

标签: html css navigationbar

我希望导航栏没有顶部边框,但即使我将“margin”设置为0px,也会有一点空间。

我如何删除该空间?

代码:

#navigationBar {
  margin: 0px;
  padding: 0px;
  overflow: hidden;
  background-color: #333;
}

li {
  display: inline;
  float: left;
  display: block;
  color: white;
  text-align: center;
  padding: 14px 16px;
  margin: 0px;
  text-decoration: none;
}

.active {
  background-color: #999999;
}

li a {
  display: block;
  color: white;
  text-align: center;
  padding: 14px 16px;
  margin: 0px;
  text-decoration: none;
}
<nav>
  <ul id="navigationBar">
    <li class="active">Site1</li>
    <li>Site2</li>
    <li>Site3</li>
    <li>Site4</li>
    <li>Site5</li>
  </ul>
</nav>

2 个答案:

答案 0 :(得分:2)

您尚未删除body和html的默认边距。加上这个:

html,body{margin:0}

&#13;
&#13;
body,html{margin:0}
#navigationBar {
        margin: 0px;
        padding: 0px;
        overflow: hidden;
        background-color: #333;
    }

    li {
        display: inline;
        float: left;
            display: block;
        color: white;
        text-align: center;
        padding: 14px 16px;
        margin: 0px;
        text-decoration: none;
    }

    .active {
        background-color: #999999;
    }

    li a {
        display: block;
        color: white;
        text-align: center;
        padding: 14px 16px;
        margin: 0px;
        text-decoration: none;
        
        }
&#13;
<nav>
  <ul id="navigationBar">
      <li class="active">Site1</li>
      <li>Site2</li>
      <li>Site3</li>
      <li>Site4</li>
      <li>Site5</li>
  </ul>
</nav>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

使用eric meyers reset css重置所有预设的边距等,然后删除默认边距。