gpt4 book ai didi

html - Flexbox:有没有办法用可变数量的列指定相等的列宽?

转载 作者:太空宇宙 更新时间:2023-11-04 09:59:34 24 4
gpt4 key购买 nike

div.column-container {
display: flex;
}

div.column-container section {
display: flex;
flex: 1 1 auto;
padding: 20px;
}

section:nth-child(1) {
background: tomato;
}

section:nth-child(2) {
background: aqua;
}

section:nth-child(3) {
background: purple;
}
<div class="column-container">
<section>
<div>
<h2>Learn about the this</h2>
</div>
</section>
<section>
<div>
<h2>Ask the right questions</h2>
</div>
</section>
<section>
<div>
<h2>Download a guide with a long description</h2>
</div>
</section>
</div>

我知道我们可以使用以下方法显式定义宽度:

flex: 1 1 33%;

但我只是想知道是否有办法告诉 flexbox 使所有列的宽度相等,因为据我所知,flexbox 元素知道它的 sibling 的尺寸。

最佳答案

要在一行上均匀地喷洒元素,您只需1设置为flex

div.column-container {
display: flex;
}

div.column-container section {
display: flex;
flex: 1 ;/* share evenly space */
padding: 20px;
}

section:nth-child(1), section:nth-child(4) {
background: tomato;
}

section:nth-child(2) {
background: aqua;
}

section:nth-child(3) {
background: purple;
}
<div class="column-container">
<section>
<div>
<h2>Learn about the this</h2>
</div>
</section>
<section>
<div>
<h2>Ask the right questions</h2>
</div>
</section>
<section>
<div>
<h2>Download a guide with a long description</h2>
</div>
</section>
</div>
<div class="column-container">
<section>
<div>
<h2>Learn about the this</h2>
</div>
</section>
<section>
<div>
<h2>Ask the right questions</h2>
</div>
</section>
<section>
<div>
<h2>Download a guide with a long description</h2>
</div>
</section>
<section>
<div>
<h2>Learn about the this</h2>
</div>
</section>
</div>

关于html - Flexbox:有没有办法用可变数量的列指定相等的列宽?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38443429/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com