英文:
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>
其他块的宽度都是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 -->
<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>
<!-- end snippet -->
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
移除 width
和 margin
在头部添加 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
在标题部分:
- 删除宽度
在 #main 部分:
- 删除宽度
- 删除边距
在 #menu div 部分:
- 删除所有内容,只添加左边距
演示: 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 ?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论