column-count
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2017.
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
/* 关键字值 */
column-count: auto;
/* <integer> 值 */
column-count: 3;
/* 全局值 */
column-count: inherit;
column-count: initial;
column-count: revert;
column-count: revert-layer;
column-count: unset;
取值
auto
-
用来表示列的数量由其他 CSS 属性指定,例如
column-width
。 <integer>
-
是个严格的正整型
<integer>
,用来描述元素内容被划分的理想列数。假如column-width
也被设置为非零值,此参数仅表示所允许的最大列数。
形式定义
形式语法
column-count =
auto |
<integer [1,∞]>
例子
将段落拆分为三列
HTML
html
<p class="content-box">
这是一段使用了 CSS <code>column-count</code>
属性分割成三列的文字。文字平均分布在各列中,这是最后一段内容。
</p>
CSS
css
.content-box {
column-count: 3;
}
结果
规范
Specification |
---|
CSS Multi-column Layout Module Level 1 # cc |
浏览器兼容性
参见
column-width
、columns
简写属性column-rule-color
、column-rule-style
、column-rule-width
、column-rule
简写属性- 多列布局(学习多列布局属性)
- 多列式布局的基础概念