简体   繁体   English

如何在纯CSS2中模拟多列布局?

[英]How to emulate multi-column layout in pure CSS2?

Basically I want to make text "flow" from one column to another in a single container element and make it without CSS3/JS. 基本上,我想在单个容器元素中使文本从一列“流”到另一列,并使其不使用 CSS3 / JS。 Here is an example how it should looks like. 这是一个示例,其外观应为。 It shouldn't be exactly a single element, it just need to contain whole text at once. 它不应该只是一个元素,而只需一次包含整个文本。

 .container { -moz-column-width: 20em; -moz-columns: 20em; -webkit-columns: 20em; columns: 20em; } 
 <div class="container">Lorem ...</div> 

or 要么

 .container { column-count: 3; column-width: 30%; column-gap: 40px; } 
 <div class="container">Lorem ...</div> 

Codepen https://codepen.io/Apxa/pen/yzgOpv https://codepen.io/Apxa/pen/yzgJmL Codepen https://codepen.io/Apxa/pen/yzgOpv https://codepen.io/Apxa/pen/yzgJmL

This is simply impossible. 这根本不可能。 CSS 2 has no way to do that. CSS 2无法做到这一点。

This is why it is being added in the CSS Multi-column Layout Module any why people used JavaScript to achieve that effect in the past. 这就是为什么在过去人们使用JavaScript实现这种效果的任何原因都将其添加到CSS多列布局模块中的原因。

The closest you can get is to manually create the columns, but picking a point for the text to move to the next column and putting the two blocks of text in different elements (which can be laid out with floating or any other pre-flexbox technique for putting blocks side by side). 您可以得到的最接近的方法是手动创建列,但要选择一个要移至下一列的文本,然后将两个文本块放在不同的元素中(可以使用浮动或其他任何pre-flexbox技术进行布置)并排放置块)。 Differences between font size, column width, etc makes this impractical. 字体大小,列宽等之间的差异使此操作不可行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM