网格自动适应固定最大宽度
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
grid-gap: 8px;
}
.item {
height: 32px;
background: red;
}
<div class="grid">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
我创建了一个具有自动调整和最小最大的网格布局。但有一件事我想不通。如果没有足够的项目,我不希望我的列太宽。基本上,我希望网格列为 1fr,除非 1fr 大于某个固定值(如 200px)。有办法实现吗?
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
grid-gap: 8px;
}
.item {
height: 32px;
background: red;
}
<div class="grid">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
I've created a grid layout with auto-fit and minmax. But there is one thing i can't figure out. If there is not enough items, I don't want my columns to be too wide. Basically, I want a grid column to be 1fr unless 1fr is bigger then some fixed value (like 200px). Is there a way to implement this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的意思是这样吗?
Do you mean like this?