使用边距时为什么会影响其他类别

时间:2019-02-06 12:47:21

标签: html css

我只想给loginContainer类添加空白,但这也会影响Navbar为什么?

#loginContainer {
  width: 500px;
  height: 400px;
  background-color: #CCCCCC;
  text-align: center;
  margin: 100px auto;
}

#navbar {
  width: 100%;
  height: 50px;
  overflow: hidden;
  box-shadow: 2px 2px 1px 1px #CCCCCC;
  background-color: white;
  position: fixed;
}
<div id="navbar">
  <div id="navbarLeft">
  </div>enter code here
  <div id="navbarMenu">
    <ul>
      <li class="menuCell">LGN</li>
      <li class="menuCell">BBS</li>
    </ul>
  </div>
</div>
<!-- login form section -->
<div id="loginContainer">
  <div id="loginBox">
    <h1 class="loginText">Login</h1>
    <input type="text" class="inputBox" placeholder="ID" name="userID" maxlength="20">
    <input type="password" class="inputBox" placeholder="PASSWORD" name="userPassword" maxlength="20">

  </div>
</div>

1 个答案:

答案 0 :(得分:1)

#navbar ( top: 0;left : 0 ; right : 0)上添加CSS,这将为您提供帮助。

#loginContainer{
    width: 500px;
    height: 400px; 
    background-color: #CCCCCC;
    text-align: center;
    margin: 100px auto;
}
#navbar{
    width: 100%;
    height: 50px;
    overflow: hidden;
    box-shadow: 2px 2px 1px 1px #CCCCCC;
    background-color: white;
    position: fixed;
    top: 0;
}
    <div id = "navbar">
      <div id = "navbarLeft">
      </div>enter code here
      <div id = "navbarMenu">
          <ul>
              <li class = "menuCell">LGN</li>
              <li class = "menuCell">BBS</li>
          </ul>
      </div>
  </div>
  <!-- login form section -->
  <div id = "loginContainer">
      <div id = "loginBox">
          <h1 class = "loginText">Login</h1>
          <input type = "text" class = "inputBox" placeholder = "ID" name = "userID" maxlength="20">
          <input type = "password" class = "inputBox" placeholder = "PASSWORD" name = "userPassword" maxlength="20">

      </div>
  </div>