column-width CSS property sets the ideal column width in a multi-column layout. The container will have as many columns as can fit without any of them having a width less than the column-width value. If the width of the container is narrower than the specified value, the single column's width will be smaller than the declared column width.

The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

This property can help you create responsive designs that fit different screen sizes. Especially in the presence of the column-count property (which has precedence), you must specify all related length values to achieve an exact column width. In horizontal text these are width , column-width , column-gap ,和 column-rule-width .

句法

/* Keyword value */
column-width: auto;
/* <length> values */
column-width: 60px;
column-width: 15.5em;
column-width: 3.3vw;
/* Global values */
column-width: inherit;
column-width: initial;
column-width: unset;
					

column-width property is specified as one of the values listed below.

<length>

Indicates the optimal column width. The actual column width may differ from the specified value: it may be wider when necessary to fill available space, and narrower when the available space is too small. The value must be strictly positive or the declaration is invalid. Percentage values are also invalid.

auto
The width of the column is determined by other CSS properties, such as column-count .

形式定义

初始值 auto
适用于 Block containers except table wrapper boxes
继承 no
计算值 the absolute length, zero or larger
动画类型 a length

形式句法

<length> | auto
					

范例

Setting column width in pixels

HTML

<p class="content-box">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.
</p>
					

CSS

.content-box {
  column-width: 100px;
}
					

结果

规范

规范 状态 注释
CSS Box Sizing Module Level 3
The definition of 'column-width' in that specification.
工作草案 Adds intrinsic sizes via the keywords min-content , max-content ,和 fit-content .
CSS Multi-column Layout Module
The definition of 'column-width' in that specification.
工作草案 初始定义。

浏览器兼容性

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
column-width Chrome 完整支持 50 Edge 完整支持 12 Firefox 完整支持 50
完整支持 50
不支持 1.5 — 74 Prefixed 注意事项
Prefixed Implemented with the vendor prefix: -moz-
注意事项 Prior to version 37, multiple columns didn't work with display: table-caption elements.
IE 完整支持 10 Opera 完整支持 11.1 Safari 完整支持 9 WebView Android 完整支持 50 Chrome Android 完整支持 50 Firefox Android 完整支持 50
完整支持 50
完整支持 4 Prefixed 注意事项
Prefixed Implemented with the vendor prefix: -moz-
注意事项 Prior to version 37, multiple columns didn't work with display: table-caption elements.
Opera Android 完整支持 11.1 Safari iOS 完整支持 9 Samsung Internet Android 完整支持 5.0
Intrinsic sizes Experimental Chrome 不支持 No Edge 不支持 No Firefox 不支持 No IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 不支持 No Chrome Android 不支持 No Firefox Android 不支持 No Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 不支持 No

图例

完整支持

完整支持

不支持

不支持

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

见实现注意事项。

见实现注意事项。

要求使用供应商前缀或不同名称。

要求使用供应商前缀或不同名称。

另请参阅

元数据

  • 最后修改: