简体   繁体   English

我如何将这个 header 与 flexbox 垂直对齐?

[英]How can i vertically align this header with flexbox?

still learning flexbox. I can´t find the reason about how the items on the nav element are not vertically aligned with the h1 text.仍在学习 flexbox。我找不到关于 nav 元素上的项目如何不与 h1 文本垂直对齐的原因。 Would love some help.会喜欢一些帮助。 Link for the codepen at the end. codepen 的链接在最后。

The expected result should be both the nav and the h1, inside the.main-header, vertically aligned.预期的结果应该是 nav 和 h1,在 .main-header 内,垂直对齐。


HTML: HTML:

    <div class="container">
      <header class="main-header clearfix">
        <h1>📘 The Code Magazine</h1>

        <nav>
          <!-- <strong>This is the navigation</strong> -->
          <a href="blog.html">Blog</a>
          <a href="#">Challenges</a>
          <a href="flexbox.html">Flexbox</a>
          <a href="css-grid.html">CSS Grid</a>
        </nav>
      </header>
</div>

CCS:中国船级社:

* {
  /* border-top: 10px solid #1098ad; */
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
body {
  color: #444;
  font-family: sans-serif;

  border-top: 10px solid #1098ad;
  position: relative;
}

.main-header {
  background-color: #f7f7f7;
  /* padding: 20px;
  padding-left: 40px;
  padding-right: 40px; */
  padding: 20px 40px;
  margin-bottom: 60px;
  /* height: 80px; */
}

nav {
  font-size: 18px;
  /* text-align: center; */
}

h1,
h2,
h3 {
  color: #1098ad;
}

h1 {
  font-size: 26px;
  text-transform: uppercase;
  font-style: italic;
}

a:link {
  color: #1098ad;
  text-decoration: none;
}

a:visited {
  /* color: #777; */
  color: #1098ad;
}

a:hover {
  color: orangered;
  font-weight: bold;
  text-decoration: underline orangered;
}

a:active {
  background-color: black;
  font-style: italic;
}

nav a:link {
  /* background-color: orangered;
  margin: 20px;
  padding: 20px;
  
  display: block; */
  margin-right: 30px;
  display: inline-block;
}

.main-header {
  display: flex;
  align-items: center;
}

Here is the link for the codepen:这是codepen的链接:

https://codepen.io/Swanbe/pen/OJzpjor https://codepen.io/Swanbe/pen/OJzpjor

Thanks in advance!提前致谢!

For past 10 minutes, I have been debugging your code.在过去的 10 分钟里,我一直在调试您的代码。 Wrote another code like this to see if the problem persists.像这样编写另一个代码以查看问题是否仍然存在。 But that was vertically aligned.但那是垂直对齐的。 So I dug deeper and tried changing and tags.所以我深入挖掘并尝试更改和标记。 Nothing Great.没什么了不起的。 .... Until I just removed that blue rubber(Emoji or whatever you call that ) and added a property in nav. .... 直到我刚刚删除了那个蓝色橡胶(表情符号或任何你称之为的东西)并在导航中添加了一个属性。

    nav {
    height: 100px;
    display: flex;
    flex-direction: row;
    align-items: center;}

and that's it.就是这样。 Try removing that emoji and see if it helps.尝试删除该表情符号,看看是否有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM