大网数据广告活动
Web 标准与前端开发

columns

· 52CE 我爱测

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

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

CSS Demo: columns

columns: 2;
columns: 6rem auto;
columns: 12em;
columns: 3;
<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 {
  min-width: 21rem;
  text-align: left;
}

它是一个简写属性,可在单个方便的声明中设置 column-width 和 column-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 。

正式语法

例子

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

例子

规范

浏览器兼容性

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。