CSS中的最小尺寸相等宽度包装列
我的HTML中有任意数量的元素,其中包含任意内容。我希望它们在列中对齐,并且都具有相同的尺寸。如果一行溢出,我希望它们包裹,但仍然保持相同的尺寸。每列的大小应尽可能小,即最大的列确定所有列的大小。
出于这篇文章的目的,我的HTML看起来像这样:
<div class="row">
<div>Col 1</div>
<div>Col 2</div>
<div>Col 3</div>
</div>
我尝试的第一件事是带有auto-fit
的CSS网格:
.row {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
}
这有效,但是这些列的最大宽度为100px,它们不能超越超出:
I have an arbitrary number of elements in my HTML with arbitrary content. I want them to be aligned in columns and all have the same size. If a row overflows, I want them to wrap, but still keep the same size. The size of every column should be as small as possible, i.e. the largest column determines the size for all of them.
For the purposes of this post, my HTML looks like this:
<div class="row">
<div>Col 1</div>
<div>Col 2</div>
<div>Col 3</div>
</div>
The first thing I tried was CSS Grid with auto-fit
:
.row {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
}
This works, but the columns have a maximum width of 100px that they cannot grow beyond:
https://codepen.io/diesieben07/pen/qBxMXXj
As has been discussed in many other questions, using auto-fit with min-content is not allowed per the spec.
How can I achieve the desired layout? Flex or other layout options are also welcome if they work better for this case.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要解决您的列问题,请应用以下CSS代码。希望您的问题能解决。
To solve your column issue, apply the following css code. I hope your problem will be solved.