小智 8
是的,flexbox是最简单的方法。
在容器元素上:
.container {
display: flex;
flex-direction: column;
justify-content: space-between;
}
Run Code Online (Sandbox Code Playgroud)
在子元素上:
.container div {
flex: 1;
width: 100%
}
Run Code Online (Sandbox Code Playgroud)
对于元素之间的间距,只需在容器中添加填充,并在子级中添加底边距。
样式如下所示:
.container {
/* Same as above, and */
padding: 20px;
}
.container div {
/* Same as above, and */
margin-bottom: 20px;
}
.container div:last-of-type{
margin-bottom: 0;
/* So that spacing is even at bottom and top of container */
}
Run Code Online (Sandbox Code Playgroud)
(当您发布答案时,我正在输入此字,因此无论如何我都提出了它)
Roc*_*160 -1
像往常一样,无论我搜索多久,我在提出问题后都会立即找到答案。:D
对于那些好奇的人,或者为了我自己的未来参考:Flexbox 的 justify 确实有效,您只需要更多选项:
HTML:
<div id="outer-container">
<div class="inner-element"></div>
<div class="inner-element"></div>
<div class="inner-element"></div>
<div class="inner-element"></div>
<div class="inner-element"></div>
<div class="inner-element"></div>
<div class="inner-element"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
#outer-container {
height: 250px;
width: 200px;
background: red;
display: flex;
justify-content: space-around;
flex-direction: column;
}
.inner-element {
width: 200px;
height: 10px;
background: blue;
}
Run Code Online (Sandbox Code Playgroud)
https://css-tricks.com/almanac/properties/j/justify-content/
| 归档时间: |
|
| 查看次数: |
9292 次 |
| 最近记录: |