html - minmax(auto, auto) 中的第一个“自动”计算为什么?
问题描述
我对 中的第一个auto
值感兴趣minmax(auto, auto)
。
我注意到auto
将是长度:当网格项min-width|width: auto;
和200px
if时最长单词的宽度min-width|width: 200px;
。
我读过“如果用作最小值,则自动值表示单元格可以达到的最大最小尺寸。这个“最大最小尺寸”不同于 min-content 值,由 min-width/min-height 指定。 " (https://bitsofco.de/how-the-minmax-function-works/)。
为了理解这个斜体短语,是不是这样:width: 200px
实际上也设置min-width
为 200px?
否则,我想知道为什么作者忽略了 plainwidth
也将决定auto
.
解决方案
我的问题是它说“最大最小尺寸”是“由最小宽度指定”。但是,当您将纯文本添加
width
到网格项目时,该项目也不会缩小到其width
. 我可以理解这width
只是暗示min-width
吗?
默认情况下,网格/弹性项目不能小于其定义的长度或内容大小(以较小者为准)。默认设置是min-width: auto
(内联/行方向)和min-height: auto
(块/列方向)。
以下是完整的解释:
您需要覆盖此设置(例如)以查看和min-width: 0
之间的区别。width
min-width
这里有几个例子(使用 flex):
article {
display: flex;
}
article:nth-of-type(1) > section {
width: auto;
flex-grow: 1;
}
article:nth-of-type(2) > section {
width: 400px;
flex-grow: 1;
}
article:nth-of-type(3) > section {
width: 400px;
flex-grow: 1;
min-width: 250px;
flex-shrink: 1;
}
article:nth-of-type(4) > section {
width: 400px;
flex-grow: 1;
min-width: 0;
/* can also use overflow property with any value other than `visible` */
}
/* non-essential demo styles */
article {
margin-bottom: 25px;
}
section {
white-space: nowrap;
height: 50px;
background-color: lightgreen;
border: 1px solid #ccc;
display: flex;
align-items: center;
}
body {
margin: 25px 50px;
}
<code>width: auto & min-width: auto (default)</code>
<article>
<section>With these settings, this item CANNOT shrink past its content size. Resize horizontally to see.</section>
</article>
<code>width: 400px & min-width: auto (default)</code>
<article>
<section>With these settings, this item CAN shrink past its content size, but CANNOT shrink past its defined width.</section>
</article>
<code>width: 400px & min-width: 200px (override)</code>
<article>
<section>With these settings, this item CAN shrink past its content size, but CANNOT shirnk past its min size.</section>
</article>
<code>width: 400px & min-width: 0 (override)</code>
<article>
<section>With these settings, this item CAN shrink past its content size AND its defined width.</section>
</article>
jsFiddle 演示
推荐阅读
- python - combine() 参数 2 必须是 datetime.time,而不是 Series
- python - 如何获得支持范围从最多零到无穷大的所有 SciPy 发行版?
- c# - 如何在 Azure WebJob 中通过 DI 配置日志记录
- c - 计算没有进来,我做错了什么
- wordpress - 如何强制浏览器加载新的 WordPress 站点而不是缓存站点
- python - 多对多字段和 request.user 不工作
- c# - 如何向 EF 核心中的现有数据添加新的外键属性?
- python - 出现错误 AttributeError: 'bool' 对象在尝试拟合机器学习模型时没有属性 'transpose'
- android - 无论设备在空间中的方向如何,如何计算设备的垂直运动?
- python - 如何在 Django v3 中测试相关模型