试一试
min-width: 150px;
min-width: 20em;
min-width: 75%;
min-width: 40ch;
<section class="default-example" id="default-example">
<div class="transition-all" id="example-element">
Change the minimum width.
</div>
</section>
#example-element {
display: flex;
flex-direction: column;
background-color: #5b6dcd;
height: 80%;
justify-content: center;
color: white;
}
语法
css
/* <length> value */
min-width: 3.5em;
min-width: anchor-size(width);
min-width: anchor-size(--my-anchor self-inline, 200%);
/* <percentage> value */
min-width: 10%;
/* Keyword values */
min-width: max-content;
min-width: min-content;
min-width: fit-content;
min-width: fit-content(20em);
min-width: stretch;
/* Global values */
min-width: inherit;
min-width: initial;
min-width: revert;
min-width: revert-layer;
min-width: unset;
值
<length>-
将
min-width定义为绝对值。 <percentage>-
将
min-width定义为包含块宽度的百分比。 auto-
默认值。指定元素的自动值来源取决于其显示值。对于块级盒、行内盒、行内块以及所有表格布局盒,
auto解析为0。对于弹性项目和网格项目,最小宽度值为指定的建议尺寸(例如
width属性的值)、转移尺寸(如果元素设置了aspect-ratio且高度是确定的尺寸,则计算得出),否则使用min-content尺寸。如果弹性或网格项目是滚动容器,或者如果网格项目跨越多个弹性列轨道,则自动最小尺寸为0。 max-content-
固有的首选
min-width。 min-content-
固有的最小
min-width。 fit-content-
使用可用空间,但不超过
max-content,即min(max-content, max(min-content, stretch))。 fit-content(<length-percentage>)-
使用
fit-content公式,并将可用空间替换为指定参数,即min(max-content, max(min-content, argument))。 stretch-
将元素外边距盒的最小宽度限制为其包含块的宽度。它试图使外边距盒填充包含块中的可用空间,因此在某种程度上行为类似于
100%,但将结果尺寸应用于外边距盒,而不是由 box-sizing 确定的盒。注意:要查看浏览器用于
stretch值的别名及其实现状态,请参阅浏览器兼容性部分。
正式定义
正式语法
min-width =
auto |
<length-percentage [0,∞]> |
min-content |
max-content |
fit-content( <length-percentage [0,∞]> ) |
<calc-size()> |
<anchor-size()> |
stretch |
fit-content |
contain
<length-percentage> =
<length> |
<percentage>
<calc-size()> =
calc-size( <calc-size-basis> , <calc-sum> )
<anchor-size()> =
anchor-size( [ <anchor-name> || <anchor-size> ]? , <length-percentage>? )
<calc-size-basis> =
<size-keyword> |
<calc-size()> |
any |
<calc-sum>
<calc-sum> =
<calc-product> [ [ '+' | '-' ] <calc-product> ]*
<anchor-name> =
<dashed-ident>
<anchor-size> =
width |
height |
block |
inline |
self-block |
self-inline
<calc-product> =
<calc-value> [ [ '*' | / ] <calc-value> ]*
<calc-value> =
<number> |
<dimension> |
<percentage> |
<calc-keyword> |
( <calc-sum> )
<calc-keyword> =
e |
pi |
infinity |
-infinity |
NaN
示例
设置最小元素宽度
css
table {
min-width: 75%;
}
form {
min-width: 0;
}
规范
| 规范 |
|---|
| CSS Box Sizing Module Level 4 # sizing-values |
浏览器兼容性
加载中…