【问题标题】:Flexbox Justify Content Space Between items are not evenly distributedFlexbox Justify 项目之间的内容空间分布不均匀
【发布时间】:2021-04-14 08:35:32
【问题描述】:

我有这个带有 flexbox 的导航栏。我使用justify-content: space-between,但似乎这些项目分布不均匀,因为中心项目有点在左侧。有什么我想念的吗?很抱歉这个基本问题。

How it currently looks like 和 how it should look like

Codepen:https://codepen.io/joxs546/pen/qBRYZLa

* {
  box-sizing: border-box;
  padding: 0;
  margin: 0;
  background-color: #e2dfe3;
}

.logo {
  height: 85px;
  width: 85px;
  display: inline-block;
  cursor: pointer;
  background: url('https://dummyimage.com/400x400/000/fff') no-repeat;
  background-size: contain;
}

.logo:hover {
  background: url('https://dummyimage.com/400x400/000/ffff') no-repeat;
  background-size: contain;
}

li,
a,
button {
  font-family: PT Sans, sans-serif;
  font-weight: bold;
  font-size: 18px;
  color: black;
  text-decoration: none;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 30px 10%;
}

.nav-ul {
  list-style: none;
}

.nav-ul li {
  padding: 0px 40px;
  display: inline-block;
}

.nav-ul li a {
  transition: all 0.3s ease 0s;
}

.nav-ul li a:hover {
  color: cornflowerblue;
}

button {
  padding: 9px 25px;
  background-color: cornflowerblue;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  transition: all 0.3s ease 0s;
}

button:hover {
  color: white;
}
<header>
  <div class="logo">
  </div>
  <nav class="nav">
    <ul class="nav-ul">
      <li> <a href="#">Services</a></li>
      <li> <a href="#">Project</a></li>
      <li> <a href="#">About</a></li>
    </ul>
  </nav>
  <a class="nav-button" href="#"></a><button>Contact</button>
</header>

【问题讨论】:

    标签: javascript html css


    【解决方案1】:

    在&lt;a&gt; 标签内使用&lt;button&gt;Contact&lt;/button&gt;。 如果你想均匀地填充空间,你也可以使用justify-content: space-evenly;。

    【讨论】:

      【解决方案2】:

      有一个空的a 标记占用了一些空间。要么应该从 HTML 中删除它,要么应该包装 button。其他一切都很完美。

      <a class="nav-button" href="#">
          <button>Contact</button>
      </a>
      

      【讨论】:

      • 哦,我现在明白了。谢谢您的帮助。我很感激一直试图找出我想念的东西。我的错。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-23
      • 2011-12-29
      • 1970-01-01
      • 2020-10-05
      • 2022-06-10
      • 1970-01-01
      • 2019-04-04
      相关资源
      最近更新 更多