column-count CSS 属性将一个元素的内容分成指定数量的列。
CSS Demo: column-count
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;
}
语法
/* 关键字值 */
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 也被设置为非零值,此参数仅表示所允许的最大列数。
形式定义
形式语法
例子
将段落拆分为三列
HTML
<p class="content-box">
这是一段使用了 CSS <code>column-count</code>
属性分割成三列的文字。文字平均分布在各列中,这是最后一段内容。
</p>
CSS
.content-box {
column-count: 3;
}
结果
将段落拆分为三列
规范
浏览器兼容性
参见
- column-width、columns 简写属性
- column-rule-color、column-rule-style、column-rule-width、column-rule 简写属性
- 多列布局(学习多列布局属性)
- 多列式布局的基础概念
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
