代码之家  ›  专栏  ›  技术社区  ›  user7907740

如何使填充响应

  •  2
  • user7907740  · 技术社区  · 6 年前

    我刚开始学习HTML和CSS,我真的很难适应快速响应的设计。我想让导航栏反应灵敏,我认为最好的方法是编辑填充。如果有人能给我一些建议,我会非常感激。

    .navbar-left {
      float: left;
      font-size: 16px;
      color: black;
      text-align: center;
      padding: 36px 29px;
      text-decoration: none;
      font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
    }
    
    .navbar-center {
      float: left;
      font-size: 30px;
      color: black;
      text-align: center;
      padding: 27px 311px;
      text-decoration: none;
      font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
    }
    
    .navbar-right {
      float: left;
      font-size: 16px;
      color: black;
      text-align: center;
      padding: 36px 29px;
      text-decoration: none;
      font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
    }
    
    .navbar-left:hover,
    .navbar-right:hover {
      background-color: #f8f8f8;
    }
    <nav>
      <a class="navbar-left" href="bio.html">About</a>
      <a class="navbar-left" href="resume.html">Resume</a>
    </nav>
    
    <nav>
      <a class="navbar-center" href="index.html">Sydnie Knowlton</a>
    </nav>
    
    <nav>
      <a class="navbar-right" href="works.html">Portfolio</a>
      <a class="navbar-right" href="contact.html">Contact</a>
    </nav>
    1 回复  |  直到 6 年前
        1
  •  1
  •   Taki    6 年前

    将宽度设置为三个 nav 33.33% 然后把它们都放到左边

    不要依赖侧垫,使用 width:50% 因此 导航 填满里面的所有空间 text-align:center 使内容居中

    * {
      box-sizing: border-box;
    }
    
    nav {
      width: 33.33%;
      float: left;
    }
    
    .navbar-left {
      float: left;
      font-size: 16px;
      color: black;
      text-align: center;
      padding: 36px 2%;
      text-decoration: none;
      font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
      width: 50%;
    }
    
    .navbar-center {
      float: left;
      font-size: 30px;
      color: black;
      text-align: center;
      padding: 27px 0;
      text-decoration: none;
      font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
      text-align: center;
    }
    
    .navbar-right {
      float: right;
      font-size: 16px;
      color: black;
      text-align: center;
      padding: 36px 2%;
      text-decoration: none;
      font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
      width: 50%;
    }
    
    .navbar-left:hover,
    .navbar-right:hover {
      background-color: #f8f8f8;
    }
    <nav>
      <a class="navbar-left" href="bio.html">About</a>
      <a class="navbar-left" href="resume.html">Resume</a>
    </nav>
    
    <nav>
      <a class="navbar-center" href="index.html">Sydnie Knowlton</a>
    </nav>
    
    <nav>
      <a class="navbar-right" href="works.html">Portfolio</a>
      <a class="navbar-right" href="contact.html">Contact</a>
    </nav>