column-count

Baseline 已广泛支持

此特性已得到良好确立,可跨多种设备和浏览器版本使用。自 2017 年 3 月起,所有浏览器均支持此特性。

column-count CSS 属性将元素内容拆分为指定数量的列。

试一试

column-count: 2;
column-count: 3;
column-count: 4;
column-count: auto;
column-width: 8rem;
<section id="default-example">
  <p id="example-element">
    London. Michaelmas term lately over, and the Lord Chancellor sitting in
    Lincoln's Inn Hall. Implacable November weather. As much mud in the streets
    as if the waters had but newly retired from the face of the earth, and it
    would not be wonderful to meet a Megalosaurus, forty feet long or so,
    waddling like an elephantine lizard up Holborn Hill.
  </p>
</section>
#example-element {
  width: 100%;
  text-align: left;
}

语法

css
/* Keyword value */
column-count: auto;

/* <integer> value */
column-count: 3;

/* Global values */
column-count: inherit;
column-count: initial;
column-count: revert;
column-count: revert-layer;
column-count: unset;

auto

列的数量由其他 CSS 属性决定,例如 column-width

<integer>

一个严格正的 <integer>,描述了元素内容将流入的理想列数。如果 column-width 也被设置为非 auto 值,它仅表示允许的最大列数。

正式定义

初始值auto
应用于块容器,除了表格包装盒
继承性
计算值同指定值
动画类型一个整数

正式语法

column-count = 
auto |
<integer [1,∞]>

示例

将一个段落拆分为三列

HTML

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

CSS

css
.content-box {
  column-count: 3;
}

结果

规范

规范
CSS Multi-column Layout Module Level 1
# cc

浏览器兼容性

另见