css - 对齐元素 : center not working in flexbox

我正在尝试垂直对齐 display: flex; 中的 nav 栏的 tex。 我使用了以下代码,但文本仍然与 nav 容器的顶部对齐,不会向下移动到中心。 你能帮我理解我做错了什么吗?我尝试将 align-items: center; 移动到 CSS 中的 nav{}nav 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;
}
<nav>
  <ul>
    <li>About Us</li>
    <li>Event Schedule</li>
    <li>Contact Us</li>
  </ul>
</nav>

最佳答案

只需将 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;
}
<nav>
  <ul>
    <li>About Us</li>
    <li>Event Schedule</li>
    <li>Contact Us</li>
  </ul>
</nav>

https://stackoverflow.com/questions/62937395/

相关文章:

r - 错误 : Must subset columns with a valid subscrip

r - 为什么同一个查询使用 dplyr 在不同的 R session 上返回不同的结果?

c - 浅/深复制术语是否适用于没有引用的对象?

python-3.x - 可以将我的临时文件放入我的应用程序中的 tmp/目录吗?

python - 为什么我会收到 KeyError : 0

html - 在 flex 中将 div 的内容右对齐

azure-devops - 在 YAML 部署作业中部署后检查应用程序运行状况端点的最佳方法?

python - 如何在 Python 中读取 SPSS aka (.sav)

vue.js - Nuxt : Open component/page as modal with

r - 对于循环存储问题