1. 面向开发者的 Web 技术
  2. CSS:层叠样式表
  3. min-width

此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

min-width

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015年7月⁩.

* Some parts of this feature may have varying levels of support.

min-width CSS 属性为给定元素设置最小宽度。它可以阻止 width 属性的应用值小于 min-width 指定的值。

尝试一下

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: #ffffff;
}

min-width 大于 max-widthwidth 时,元素的宽度将被设置为 min-width 的值。

语法

css
/* <length> 值 */
min-width: 3.5em;
/* <percentage> 值 */
min-width: 10%;
/* 关键字值 */
min-width: max-content;
min-width: min-content;
min-width: fit-content;
min-width: fit-content(20em);
/* 全局值 */
min-width: inherit;
min-width: initial;
min-width: revert;
min-width: revert-layer;
min-width: unset;

<length>

以绝对值定义 min-width

<percentage>

以包含区块的宽度百分比定义 min-width

auto

浏览器将计算并选择指定元素的 min-width

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))

形式定义

初始值 auto
适用元素all elements but non-replaced inline elements, table rows, and row groups
是否是继承属性
Percentagesrefer to the width of the containing block
计算值 the percentage as specified or the absolute length
动画类型 a length, percentage or calc();

形式语法

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;
}

规范

Specification
CSS Box Sizing Module Level 4
# sizing-values

浏览器兼容性

参见

Help improve MDN

Learn how to contribute

This page was last modified on by MDN contributors.

AltStyle によって変換されたページ (->オリジナル) /