HTML CSS Nav 得到我的 margin-top Table

HTML CSS Nav get my margin-top of Table

我有一个 position: absolute; 的侧边导航,它填满了屏幕的整个左侧,我的 table 在屏幕中间,但是如果我想应用 margin-top:50px; SideNav 也知道了。

如果我删除 position 它可以工作,但它不能再填充所有左侧。

我不知道为什么会这样,谢谢你的帮助。

body{
  height: 100vh;
  margin: 0;
  padding: 0;
  background-color: #F5F5F5;
}

.App {
  text-align: center;
}

.App-logo {
  animation: App-logo-spin infinite 20s linear;
  height: 80px;
}

.App-header {
  background-color: #222;
  height: 150px;
  padding: 20px;
  color: white;
}

.App-title {
  font-size: 1.5em;
}

.App-intro {
  font-size: large;
}

table {
  text-align: center;
  width: 500px;
  margin:auto;
  margin-right: 40%;
  border-color: #0585e1;
  border-width: 1px;
  border-style: groove;
  padding: 20px 0;
  background-color: #c9d4e8;
  border-radius: 3px;
  margin-top: 10px;
}

table input {
  width: 200px;
  border-color: #0585e1;
  border-style: groove;
  padding: 4px;
  font-size: 13px;
  background-color: #c9d4e8;
  color: #0585e1;
  margin:3px 0;
}

table td {
  color: #0585e1;

}

button {
  color: #0585e1;
  background-color: #c9d4e8;
  margin-top: 15px;
  cursor: pointer;
  width: 150px;
  font-size: 15px;
  border-color: #0585e1;
  border-style: groove;
}

#navigator {
  background: #354256;
  color: #0585e1;
  height: 100%;
  position: absolute;
}

不要将 margin-top: 50px; 应用于 <body> 元素,而是应用:

padding-top: 50px;

此外,除了为 #navigator 声明 position: absolute 之外,理想情况下,您应该提供明确的坐标。

例如

#navigator {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  color: #0585e1;
  background-color: #354256;
}