【问题标题】:HTML & CSS - Centering text in header inbetween logo and buttonHTML & CSS - 在标志和按钮之间的标题中居中文本
【发布时间】:2016-10-22 15:37:22
【问题描述】:

如何将导航链接与标题对齐? 这是我目前拥有的: 但是,我真的很想让链接在标题中垂直对齐,如下所示: 我该怎么做? 下面是我的 CSS 和 HTML。

html, body {
    margin: 0;
    padding: 0;
}

body {
  font-family: 'Open Sans', sans-serif;
}

.wrapper {
  width: 1100px;
  max-width: 90%;
  margin: 0 auto;
}

#top_header {
  position: fixed;
  left: 0px;
  top: 0px;
  right: 0px;
  background-color: #26ABF5;
  height: 70px;
  vertical-align: middle;
}

#logo_top {
  display: inline-block;
  width: 53px;
  padding-top: 8px;
}

#main_nav {
  display: inline-block;
  font-size: 12px;
  padding-left: 170px;
}

#main_nav a {
  color: #fff;
  font-weight: 400;
  text-decoration: none;
  margin-left: 6em;
}

.button {
  float: right;
  justify-content: center;
  display: flex;
  width: 101px;
  margin-top: 14px;
  padding-top: 9px;
  padding-bottom: 9px;
  border-radius: 2px;
  background-color: #fff;
  text-decoration: none;
  font-family: 'Open Sans', sans-serif;
  color: #26abf5;
  font-size: 13px;
  font-weight: 600;
}
<body>
    <header id="top_header">
      <div class="wrapper">
        <a href="index.html"><img id="logo_top" draggable="false" src="images/logo1.png"></a>
          <nav id="main_nav">
            <a href="#">FORSIDE</a>
            <a href="#">HVAD TILBYDER VI?</a>
            <a href="#">PRISER</a>
            <a href="#">OM OS</a>
          </nav>
            <a class="button" href="#">LOG IND</a>
      </div>
  </body>

【问题讨论】:

    标签: html css header navigation


    【解决方案1】:

    使用vertical-align 的行高。我在#main_nav 中添加该行。

    编辑:为您的徽标图片添加float: left;

    html, body {
        margin: 0;
        padding: 0;
    }
    
    body {
      font-family: 'Open Sans', sans-serif;
    }
    
    .wrapper {
      width: 1100px;
      max-width: 90%;
      margin: 0 auto;
    }
    
    #top_header {
      position: fixed;
      left: 0px;
      top: 0px;
      right: 0px;
      background-color: #26ABF5;
      height: 70px;
      vertical-align: middle;
    }
    
    #logo_top {
      display: inline-block;
      float: left;
      width: 53px;
      padding-top: 8px;
    }
    
    #main_nav {
      display: inline-block;
      font-size: 12px;
      line-height: 70px;
      padding-left: 170px;
    }
    
    #main_nav a {
      color: #fff;
      font-weight: 400;
      text-decoration: none;
      margin-left: 6em;
    }
    
    .button {
      float: right;
      justify-content: center;
      display: flex;
      width: 101px;
      margin-top: 14px;
      padding-top: 9px;
      padding-bottom: 9px;
      border-radius: 2px;
      background-color: #fff;
      text-decoration: none;
      font-family: 'Open Sans', sans-serif;
      color: #26abf5;
      font-size: 13px;
      font-weight: 600;
    }
    <body>
        <header id="top_header">
          <div class="wrapper">
            <a href="index.html"><img id="logo_top" draggable="false" src="images/logo1.png"></a>
              <nav id="main_nav">
                <a href="#">FORSIDE</a>
                <a href="#">HVAD TILBYDER VI?</a>
                <a href="#">PRISER</a>
                <a href="#">OM OS</a>
              </nav>
                <a class="button" href="#">LOG IND</a>
          </div>
      </body>

    【讨论】:

    • 这什么都没做?我可以看到,它在您的示例中居中,但是当我使用添加的徽标图像对其进行测试时,没有任何反应。
    • 另外,这里是徽标的图像,如果您想用它进行测试:
    • 即时编辑我的答案。只需要添加 float: left;为您的徽标图像。
    • 非常感谢您抽出宝贵时间!这就像一个魅力。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-13
    • 2013-06-06
    • 2014-01-08
    • 2017-08-29
    • 1970-01-01
    • 2015-06-13
    • 2020-11-15
    相关资源
    最近更新 更多