← 返回首页
column-span - CSS:层叠样式表 | MDN

此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

column-span

基线 广泛可用

自 2020年7月 起,此特性已在主流浏览器中得到支持,可在大多数设备和浏览器版本中正常使用。

CSS 属性 column-span 的值被设置为 all 时,可以让一个元素跨越所有的列。

本文内容

尝试一下

column-span: none;
column-span: all;
<section id="default-example"> <div class="multicol-element"> <p> London. Michaelmas term lately over, and the Lord Chancellor sitting in Lincoln's Inn Hall. </p> <div id="example-element">Spanner?</div> <p> 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> </div> </section>
.multicol-element { width: 100%; text-align: left; column-count: 3; } .multicol-element p { margin: 0; } #example-element { background-color: rebeccapurple; padding: 10px; color: #fff; }
css
/* 关键字值 */ column-span: none; column-span: all; /* 全局值 */ column-span: inherit; column-span: initial; column-span: revert; column-span: revert-layer; column-span: unset;

一个跨越多列的元素被称为跨越元素(spanning element)。

语法

column-span 属性可以被指定为下面列出的关键字值之一。

取值

none

元素不跨多个列。

all

元素横跨所有列。元素出现之前,出现在元素之前的正常流中的内容在所有列之间自动平衡。该元素建立一个新的区块格式化上下文。

形式定义

初始值适用元素是否是继承属性计算值动画类型
none
in-flow block-level elements
as specified
离散值

形式语法

column-span =
none |
<integer [1,∞]> |
all |
auto

<integer> =
<number-token>
此语法反映了基于 CSS Multi-column Layout Module Level 2, CSS Values and Units Module Level 4 的最新标准。并非所有浏览器都已实现全部内容。有关支持信息,请参阅浏览器兼容性

示例

使标题跨越列

在该示例中,标题跨越了文章中的所有列。

HTML

html
<article> <h2>这是一个跨越了所有的列的标题</h2> <p>h2 元素应该跨越所有列。文本的其余内容应该分布在各列中。</p> <p>这是一些使用 CSS `columns` 属性分成三列的文本。文本在各列中均匀分布。</p> <p>这是一些使用 CSS `columns` 属性分成三列的文本。文本在各列中均匀分布。</p> <p>这是一些使用 CSS `columns` 属性分成三列的文本。文本在各列中均匀分布。</p> <p>这是一些使用 CSS `columns` 属性分成三列的文本。文本在各列中均匀分布。</p> </article>

CSS

css
article { columns: 3; } h2 { column-span: all; }

结果

规范

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

浏览器兼容性

启用 JavaScript 以查看此浏览器兼容性表。

参见