gpt4 book ai didi

CSS - 等高列?

转载 作者:行者123 更新时间:2023-11-28 03:11:07 27 4
gpt4 key购买 nike

在 CSS 中,我可以这样做:

enter image description here

但我不知道如何将其更改为:

enter image description here


这可以用 CSS 实现吗?

如果是,不显式指定高度(让内容增长)怎么办?

最佳答案

网格

如今,我更喜欢网格,因为它允许将所有布局声明保留在父级上,并默认为您提供等宽的列:

.row {
display: grid;
grid-auto-flow: column;
gap: 5%;
}

.col {
border: solid;
}
<div class="row">
<div class="col">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</div>
<div class="col">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.</div>
<div class="col">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo.</div>
</div>

flexbox

如果你想让 child 控制列宽,请使用 Flexbox:

.row {
display: flex;
justify-content: space-between;
}

.col {
flex-basis: 30%;
box-sizing: border-box;
border: solid;
}
<div class="row">
<div class="col">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</div>
<div class="col">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.</div>
<div class="col">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo.</div>
</div>

关于CSS - 等高列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30454839/

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