将div固定在屏幕顶部

时间:2017-12-17 12:11:18

标签: html css

因此,我使用HTML divtable元素制作了导航栏。



.menu {
  background-color: black;
  color: white;
  font-family: Segoe UI;
}

<div class="menu">
  <table border="0" cellspacing="10">
    <tr>
      <td>Home</td>
      <td>About</td>
      <td>Login</td>
    </tr>
  </table>
</div>
&#13;
&#13;
&#13;

当然,它现在还没有完成,请不要问为什么我没有使用无序列表<ul>而不是表格。

所以,我想在屏幕顶部修复此菜单。在div之前没有留下空格。这是什么CSS代码?

3 个答案:

答案 0 :(得分:2)

&#13;
&#13;
body {
  margin: 0;
}

.menu {
  background-color: black;
  color: white;
  font-family: Segoe UI;
}
&#13;
<div class="menu">
  <table border="0" cellspacing="10">
    <tr>
      <td>Home</td>
      <td>About</td>
      <td>Login</td>
  </table>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

您可以使用css属性position : fixed;width : 100%在所有屏幕上显示

答案 2 :(得分:1)

尝试遵循CSS代码:

.menu {
  background-color: black;
  color: white;
  font-family: Segoe UI;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
}
相关问题