将div固定在屏幕顶部

问题描述 投票:1回答:3

所以,我使用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>

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

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

html css
3个回答
2
投票

body {
  margin: 0;
}

.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>
  </table>
</div>

1
投票

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


1
投票

尝试遵循CSS代码:

.menu {
  background-color: black;
  color: white;
  font-family: Segoe UI;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
}
© www.soinside.com 2019 - 2024. All rights reserved.