CSS Grid 布局的 item 最后一行,不拉伸 All In One
CSS Grid 布局的 item 最后一行,不拉伸 All In One
UI 产品需求:
- 容器宽度: 有最小值,最大值
- 每个 item 左对齐,完全填充容器宽度
- item 有最小宽度?最大宽度
- 最后一行,左对齐,不用填充全部 (不拉伸 )
效果一
📦 📦 📦 📦
📦 📦 📦 📦
📦 📦 📦 📦
📦 📦 📦 📦
📦 📦
效果二
📦 📦 📦 📦 📦
📦 📦 📦 📦 📦
📦 📦 📦 📦 📦
📦 📦 📦
??? css flex 布局的 item 最后一行,不拉伸 ❌
css functions
repeat & auto-fit & minmax & 1fr
.select-area {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
flex-wrap: wrap;
margin: 20px 0 0 20px;
overflow-y: visible;
}
.item {
min-width: 320px;
margin-bottom: 20px;
}
demo
https://codepen.io/xgqfrms/pen/BaWPXMR
bug ❌
body {
box-sizing: border-box;
padding: 10vh 10vw;
margin: 0;
}
/*
repeat & auto-fit & minmax & 1fr
*/
.box {
box-sizing: border-box;
padding: 0;
margin: 0;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
flex-wrap: wrap;
border: 1px solid red;
background: #ccc;
min-height: 400px;
// height: 400px;
// overflow-y: visible;
}
// item overflow-x bug ??? ❌
.item {
box-sizing: border-box;
// padding: 0 10px;
padding: 0;
// margin: 0;
margin: 0 10px;
min-width: 200px;
height: 50px;
background: #000;
color: #0f0;
border: 1px solid red;
text-align: center;
line-height: 50px;
}
OK
body {
box-sizing: border-box;
padding: 10vh 10vw;
margin: 0;
}
.resizable {
overflow: auto;
// 必须设置 overflow: auto; 才能 resize 容器 ✅
cursor: col-resize;
// cursor: all-resize;
// cursor: col-resize;
// cursor: row-resize;
resize: horizontal;
// resize: none;
// resize: both;
// resize: horizontal;
// resize: vertical;
// resize: block;
// resize: inline;
}
/*
repeat & auto-fit & minmax & 1fr
*/
.box {
box-sizing: border-box;
padding: 0;
margin: 0;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
flex-wrap: wrap;
border: 1px solid red;
background: #ccc;
min-height: 400px;
// height: 400px;
// overflow-y: visible;
}
.box-samll {
min-height: 200px;
margin-bottom: 30px;
}
// item overflow-x bug ??? ❌
.item {
box-sizing: border-box;
// padding: 0 10px;
padding: 0;
// margin: 0;
margin: 0 10px;
min-width: 200px;
height: 50px;
background: #000;
color: #0f0;
border: 1px solid red;
text-align: center;
line-height: 50px;
}
.item-empty {
box-sizing: border-box;
padding: 0;
margin: 0;
// flex: 0 1 auto;
// flex: 1 auto;
width: 200px;
height: 0;
}
css resize & css cursor
.resizable {
overflow: auto;
// 必须设置 overflow: auto; 才能 resize 容器 ✅
cursor: col-resize;
resize: horizontal;
}
.resizable {
overflow: auto;
// 必须设置 overflow: auto; 才能 resize 容器 ✅
cursor: col-resize;
// cursor: all-resize;
// cursor: col-resize;
// cursor: row-resize;
resize: horizontal;
// resize: none;
// resize: both;
// resize: horizontal;
// resize: vertical;
// resize: block;
// resize: inline;
}
refs
https://codepen.io/xgqfrms/pen/JYyNYK
https://www.cnblogs.com/xgqfrms/p/14866095.html
©xgqfrms 2012-2021
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/14869484.html
未经授权禁止转载,违者必究!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
2020-06-10 前端监控平台 & 架构
2020-06-10 微软 AI 公开课
2020-06-10 Suspense for Data Fetching
2019-06-10 IM SDK & websocket & chart room
2019-06-10 React Native Apps
2019-06-10 Flutter 1.5
2017-06-10 GitHub GraphQL API & GitHub REST API All In One