html - 如何创建像 Apple 一样的导航栏?

标签 html css flexbox

如何创建像 Apple 那样的导航栏?我试过了,这是我目前所拥有的:enter image description here

如您所见,按钮的间距有点偏离。我使用 justify-content: space-around 来实现这一点。我试图使间距与 Apple 网站相同,但没有成功,想知道是否有人可以帮助我。仅供引用,这里是 Apple 网站的导航栏。

enter image description here

这是我尝试过的:

.wrapper {
  height: 100vh;
}

nav {
  height: 44px;
  overflow: scroll;
  background: #323232;
}

nav ul {
  display: flex;
  height: 44px;
  justify-content: space-around;
  align-items: center;
  padding: 0;
  margin: 0;
  list-style-type: none;
}

nav li {}

nav a {
  display: block;
  color: white;
  font-size: 15px;
  font-weight: lighter;
  text-decoration: none;
  transition: 0.3s;
}

nav a:hover {
  color: #B8B8B8;
}
<div class="wrapper">
  <nav>
    <ul>
      <li><a href="#"><i class="fab fa-houzz"></i></a></li>
      <li><a href="#">Ban</a></li>
      <li><a href="#">Warn</a></li>
      <li><a href="#">Gift</a></li>
      <li><a href="#">User</a></li>
    </ul>
  </nav>
</div>

最佳答案

一些事情:

  1. Apple 在导航中应用了一个具有“最大宽度”的“容器”。已在下方添加。
  2. 我调整了一些样式以改善外观/感觉。下面的 CSS 中的注释。
  3. 如果仔细观察,apple 在链接之间有“死 Angular ”。这也存在于此标记/布局中。

如果这不能解决您的问题,那么请告知您所说的“间距关闭”是什么意思 - 具体并清楚,否则无法提供帮助。 ...:)

body {
margin: 0;
}

.wrapper {
  height: 100vh;
}

nav {
  height: 44px;
  background: #323232;
  text-align: center; /* to center the UL in the nav */
}

nav ul {
  display: flex;
  max-width: 1200px; /* change to desired width */
  /* removed height from here, apply to a elements */
  justify-content: space-around;
  align-items: center;
  padding: 0;
  margin: 0 auto; /* 0 auto allows it to self-center in the nav */
  list-style-type: none;
}

nav li {}

nav a {
  display: inline-block;
  height: 44px; /* apply the height here, pushes the li / ul to be the correct height */
  line-height: 44px; /* to get vertical centering */
  color: white;
  font-size: 15px;
  font-weight: 100;
  text-decoration: none;
  transition: 0.3s;
}

nav a:hover {
  color: #B8B8B8;
}
<div class="wrapper">
  <nav>
    <ul>
      <li><a href="#"><i class="fab fa-houzz"></i></a></li>
      <li><a href="#">Ban</a></li>
      <li><a href="#">Warn</a></li>
      <li><a href="#">Gift</a></li>
      <li><a href="#">User</a></li>
    </ul>
  </nav>
</div>

关于html - 如何创建像 Apple 一样的导航栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51248999/

相关文章:

html - 在其他跨度之间居中 div 或跨度

CSS3 导航栏(响应式)或传统背景图片

php - 从打印 CSS 中删除 JS

html - 如何使用 CSS Flexbox 将流体图像和标题居中?

html - 图像未显示在 Flex 容器中

javascript - 如何通过单击按钮调用具有不同选择选项的不同功能

javascript - 如何以编程方式单击具有 tabindex、onclick 和 id 作为属性的 div

css - 元素动画关键帧的继承

javascript - 将 div 对齐在同一行

css - 当宽度大于 flex 容器时如何计算 flex 收缩?