columns

CSS属性 columns 用来设置元素的列宽和列数。

它是一个简写属性,可在单个方便的声明中设置 column-widthcolumn-count 属性。与所有简写属性一样,任何省略的子值都将设置为其初始值

语法

/* Column width */
columns: 18em;

/* Column count */
columns: auto;
columns: 2;

/* Both column width and count */
columns: 2 auto;
columns: auto 12em;
columns: auto auto;

/* Global values */
columns: inherit;
columns: initial;
columns: unset;

columns 属性可以按任何顺序指定为下面列出的一个或两个值。

取值

<'column-width'>
理想的列宽,定义为 <length> auto 关键字。实际宽度可以更宽或更窄以适合可用空间。See column-width
<'column-count'>
元素内容应分成的理想列数,定义为 <integer> auto 关键字。如果此值和列的宽度都不是 auto ,则它仅指示允许的最大列数。请参阅 column-count

正式语法

<'column-width'> || <'column-count'>

例子

HTML

<p class="content-box">
  This is a bunch of text split into three columns
  using the CSS `columns` property. The text
  is equally distributed over the columns.
</p>

CSS

.content-box {
  columns: 3 auto;
}

Result

规范

Specification Status Comment
CSS Multi-column Layout Module
columns
Working Draft Initial definition.
初始值as each of the properties of the shorthand:
适用元素Block containers except table wrapper boxes
是否是继承属性
适用媒体visual
计算值as each of the properties of the shorthand:
Animation typeas each of the properties of the shorthand:
正规顺序per grammar

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
columnsChrome Full support 50
Full support 50
Full support 50
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Edge Full support 12
Full support 12
Full support 12
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Firefox Full support 52
Full support 52
Full support 9
Prefixed Notes
Prefixed Implemented with the vendor prefix: -moz-
Notes Prior to version 37, multiple columns didn't work with display: table-caption elements.
IE Full support 10Opera Full support 11.1
Full support 11.1
Full support 15
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Safari Full support 9
Full support 9
Full support 3
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
WebView Android Full support 50
Full support 50
Full support 2
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Chrome Android Full support 50Firefox Android Full support 52
Full support 52
Full support 22
Prefixed Notes
Prefixed Implemented with the vendor prefix: -moz-
Notes Prior to version 37, multiple columns didn't work with display: table-caption elements.
Opera Android Full support 11.1
Full support 11.1
Full support 14
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Safari iOS Full support 9
Full support 9
Full support 3.2
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Samsung Internet Android Full support 5.0

Legend

Full support  
Full support
See implementation notes.
See implementation notes.
Requires a vendor prefix or different name for use.
Requires a vendor prefix or different name for use.