column-span
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2020.
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
属性可以被指定为下面列出的关键字值之一。
取值
形式定义
形式语法
column-span =
none |
<integer [1,∞]> |
all |
auto
示例
使标题跨越列
在该示例中,标题跨越了文章中的所有列。
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;
}
结果
规范
Specification |
---|
CSS Multi-column Layout Module Level 1 # column-span |