`justify-content: space-between` 不正确。

huangapple go评论102阅读模式
英文:

Justify-content: space-between works incorrect

问题

我有以下代码:

header {
  width: 100%;
  height: 65px;
  background: #fff;
  font-size: 11px;
  font-weight: bold;
  text-transform: uppercase;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #252c3a;
}

#menu {
  width: 100%;
  display: flex;
  margin-left: 28%;
}

#menu div {
  width: 100px;
  height: 65px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
<header>
  <div id="logo">
    <img src="img/header/logo.png" alt="Logo">
  </div>
  <div id="menu">
    <div>Home</div>
    <div>Club-Life</div>
    <div>Training</div>
    <div>Instructors</div>
    <div>Contact</div>
  </div>
</header>

Chrome inspect

其他块的宽度都是100%,但头部的宽度比下面的块要大。我使用了 justify-content: space-between

英文:

i have the following code

<!-- begin snippet: js hide: false console: false babel: false -->

<!-- language: lang-css -->

header {
  width: 100%;
  height: 65px;
  background: #fff;
  font-size: 11px;
  font-weight: bold;
  text-transform: uppercase;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #252c3a;
}

#menu {
  width: 100%;
  display: flex;
  margin-left: 28%;
}

#menu div {
  width: 100px;
  height: 65px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

<!-- language: lang-html -->

&lt;header&gt;
  &lt;div id=&quot;logo&quot;&gt;
      &lt;img src=&quot;img/header/logo.png&quot; alt=&quot;Logo&quot;&gt;
  &lt;/div&gt;
  &lt;div id=&quot;menu&quot;&gt;
      &lt;div&gt;Home&lt;/div&gt;
      &lt;div&gt;Club-Life&lt;/div&gt;
      &lt;div&gt;Training&lt;/div&gt;
      &lt;div&gt;Instructors&lt;/div&gt;
      &lt;div&gt;Contact&lt;/div&gt;
  &lt;/div&gt;

<!-- end snippet -->

Chrome inspect

The width of the other blocks is 100%, but the header width gets bigger than the block below. I use justify-content: space-between.

答案1

得分: 1

移除 widthmargin

在头部添加 flex-wrap

header {
    height: 65px;
    background: #fff;
    font-size: 11px;
    font-weight: bold;
    text-transform: uppercase;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #252c3a;
    flex-wrap: wrap;
}

#menu {
    display: flex;
    flex-wrap: wrap;
}
英文:

Remove width & margin

Add flex-wrap on the header

header {
    width: 100%;
    height: 65px;
    background: #fff;
    font-size: 11px;
    font-weight: bold;
    text-transform: uppercase;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #252c3a;
    flex-wrap:wrap;
}

#menu {
    display: flex;
    flex-wrap:wrap;
}

答案2

得分: 0

在标题部分:

  1. 删除宽度

在 #main 部分:

  1. 删除宽度
  2. 删除边距

在 #menu div 部分:

  1. 删除所有内容,只添加左边距

演示: https://codepen.io/Bibeva/pen/povddJr

最终代码:

header {
    height: 65px;
    background: #fff;
    font-size: 11px;
    font-weight: bold;
    text-transform: uppercase;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #252c3a;
}

#menu {
    display: flex;
}

#menu div {
    margin: 0 0 0 30px;
}

请注意:这是代码的翻译部分,没有其他内容。

英文:

There are few things we need to do:

In header:

1. Remove width

In #main:

1. Remove width
2. Remove margin

In #menu div:

1. Remove everything and just add margin left

Demo: https://codepen.io/Bibeva/pen/povddJr

Final code:

header {
    height: 65px;
    background: #fff;
    font-size: 11px;
    font-weight: bold;
    text-transform: uppercase;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #252c3a;
}

#menu {
    display: flex;
}

#menu div {
    margin: 0 0 0 30px;
}

答案3

得分: -1

Sure, here's the translated code:

#menu {
    display: flex;
}

That's all.

英文:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

#menu {
    display: flex;
}

<!-- end snippet -->

that's all , Can you try this ?

huangapple
  • 本文由 发表于 2020年1月3日 21:25:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/59579406.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定