Google的 Chrome实验室 收 集了很多让人难以置信的基于 HTML5 Canvas 和 JavaScript 的实验项目,里面的例子都很独特,让人惊叹。我从未想过结合 HTML…
May 4, 2015
css 多栏文字流 css two columns text flow
1. 方法一 : CSS3
<!DOCTYPE html> <html> <head> <style> .newspaper { -webkit-column-count: 2; /* Chrome, Safari, Opera */ -moz-column-count: 2; /* Firefox */ column-count: 2; -webkit-column-gap: 40px; /* Chrome, Safari, Opera */ -moz-column-gap: 40px; /* Firefox */ column-gap: 40px; -webkit-column-rule: 1px solid lightblue; /* Chrome, Safari, Opera */ -moz-column-rule: 1px solid lightblue; /* Firefox */ column-rule: 1px solid lightblue; } </style> </head> <body> <p><b>Note:</b> Internet Explorer 9, and earlier versions, does not support the column-rule property.</p> <div class="newspaper"> Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. </div> </body> </html>
来源:http://www.w3schools.com/css/css3_multiple_columns.asp
参考:http://www.w3chtml.com/css3/properties/multi-column/
2. 方法二:jQuery
<div id="data" class="Column1" style="float:left;width:300px;"> <!-- data Start --> <p>This is paragraph 1. Lorem ipsum ...</p> <p>This is paragraph 2. Lorem ipsum ...</p> <p>This is paragraph 3. Lorem ipsum ...</p> <p>This is paragraph 4. Lorem ipsum ...</p> <p>This is paragraph 5. Lorem ipsum ...</p> <p>This is paragraph 6. Lorem ipsum ...</p> <p>This is paragraph 7. Lorem ipsum ...</p> <p>This is paragraph 8. Lorem ipsum ...</p> <p>This is paragraph 9. Lorem ipsum ...</p> <p>This is paragraph 10. Lorem ipsum ...</p> <p>This is paragraph 11. Lorem ipsum ...</p> <!-- data Emd--> </div> <div id="Column2" style="float:left;width:300px;"></div>
$(document).ready(function () { var size = $("#data > p").size(); $(".Column1 > p").each(function (index) { if (index >= size / 2) { $(this).appendTo("#Column2"); } }); });
原文:http://stackoverflow.com/a/3039054/4484798
demo:http://jsfiddle.net/dPUmZ/1/
或者使用插件:http://welcome.totheinter.net/columnizer-jquery-plugin/ 下载实例插件:Columnizer-jQuery-Plugin-master