xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

CSS Grid 布局的 item 最后一行,不拉伸 All In One

CSS Grid 布局的 item 最后一行,不拉伸 All In One

UI 产品需求:

  1. 容器宽度: 有最小值,最大值
  2. 每个 item 左对齐,完全填充容器宽度
  3. item 有最小宽度?最大宽度
  4. 最后一行,左对齐,不用填充全部 (不拉伸 )

效果一
📦 📦 📦 📦
📦 📦 📦 📦
📦 📦 📦 📦
📦 📦 📦 📦
📦 📦

效果二
📦 📦 📦 📦 📦
📦 📦 📦 📦 📦
📦 📦 📦 📦 📦
📦 📦 📦

??? 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, 禁止转载 🈲️,侵权必究⚠️!


posted @   xgqfrms  阅读(530)  评论(5编辑  收藏  举报
编辑推荐:
· 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
点击右上角即可分享
微信分享提示