【发布时间】:2013-10-31 11:24:21
【问题描述】:
我无法使用 CSS3 列将两个元素“放在一起”。考虑以下 HTML:
<div style="column-count: 2"> <!-- I'm aware there's more CSS rules needed -->
<div class="heading">Heading 1</div>
<div class="content">Long paragraph text goes in here lalalalala</div>
<div class="heading">Heading 2</div>
<div class="content">Some longer paragraph text goes in here</div>
</div>
在 Chrome、Firefox 和 Safari 中,它会按照我的意愿显示:
Heading 1 | Heading 2
Long paragraph text goes | Some longer paragraph text goes
in here lalalalala | in here
我使用以下 CSS 将标题和内容“粘贴”在一起 <div>s:
.heading {padding-bottom: 30px;}
.content {margin-top: -30px;}
这可确保标题不是一列中的最后一项,内容位于下一列中。然而,这正是 IE10 中发生的情况:
Heading 1 | Some longer paragraph text goes
Long paragraph text goes | in here
in here lalalalala |
Heading 2 |
请记住,每列中可能有许多 #heading 和 #content div,因此仅在标题上使用 break-after: always 是不够的。
此外,将两个元素都包装在另一个 div 中并在该 div 上添加 break-inside: avoid; 是不够的,因为 #content div 必须能够在列之间流动。
我所追求的是一些 CSS 以确保标题和内容 div 不会在分栏符处分开。
谢谢
【问题讨论】:
-
您是否尝试过将匹配的标题和内容放入一个
<section>标记中? -
是的,刚刚试过,没什么区别
-
你应该可以在标题上使用
break-after:avoid。 -
我也是这么想的,但好像也没什么区别。
标签: html css multiple-columns