侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

如果我们在CSS网格中有更多列,为什么内容大小不同?

2023-05-07 星期日 / 0 评论 / 0 点赞 / 81 阅读 / 1411 字

为什么这样: div { width: 200px; display: grid; grid: "first second" / 1fr 1fr; background-color:

... . . 为什么这样:

div {  width: 200px;  display: grid;  grid: "first second" / 1fr 1fr;  background-color: #ccc;  padding: 8px;}#first {  grid-area: first;}#second {  grid-area: second;}
<div>  <input id="first" />  <input id="second" /></div>

与此不同的是:

div {  width: 200px;  display: grid;  grid: "first first second second" / 1fr 1fr 1fr 1fr;  background-color: #ccc;  padding: 8px;}#first {  grid-area: first;}#second {  grid-area: second;}
<div>  <input id="first" />  <input id="second" /></div>

请注意,我唯一改变的是列数和每个输入占用的区域.

.

解决方法

. 这是规范的一个问题,以及如何解释1fr.

W3C bug/issue report

.

The “problem” is that 1fr resolves to minmax(auto,1fr) and this means that we need to know the size of (the parent) before resolving the size of the 1fr track (because the min track sizing function is content sized,it’s auto).

There is a quick solution to this issue from the author POV,just replacing 1fr by minmax(0px,1fr) for example.

.

..或者在这种情况下只需将min-width:0设置为子元素.

. . .. ...

广告 广告

评论区