Mar*_*kAA 2 css text-align vertical-alignment flexbox display
我正在尝试垂直对齐nav中的条形的 tex display: flex;。我使用了以下代码,但文本仍然与nav容器的顶部对齐,并且不会向下移动到中心。你能帮我理解我做错了什么吗?我尝试过在 CSS 中移动align-items: center;到nav{}andnav ul li{}但它没有改变任何东西。
nav {
background-color: aquamarine;
width: 100%;
height: 70px;
}
nav ul {
list-style: none;
display: flex;
justify-content: space-around;
align-items: center;
}
nav ul li {
font-size: 3rem;
}Run Code Online (Sandbox Code Playgroud)
<nav>
<ul>
<li>About Us</li>
<li>Event Schedule</li>
<li>Contact Us</li>
</ul>
</nav>Run Code Online (Sandbox Code Playgroud)
只需添加height: 100%到nav ul
nav {
background-color: aquamarine;
width: 100%;
height: 70px;
}
nav ul {
list-style: none;
display: flex;
justify-content: space-around;
align-items: center;
height: 100%;
}
nav ul li {
font-size: 3rem;
}Run Code Online (Sandbox Code Playgroud)
<nav>
<ul>
<li>About Us</li>
<li>Event Schedule</li>
<li>Contact Us</li>
</ul>
</nav>Run Code Online (Sandbox Code Playgroud)