2014-09-30 35 views
0

我有一個div,其中可能包含大量的文本內容。我必須將其分成兩列視圖。 (Example)。使用jQuery和CSS將動態div分成兩列

有沒有辦法使用jQuery HTML內容分裂?

+0

這個插件很不錯,可以完成這項工作。 http://welcome.totheinter.net/columnizer-jquery-plugin/ – 2014-09-30 12:53:11

回答

1

您可以使用CSS列:

div { 
 
     -webkit-column-count: 2; /* Chrome, Safari, Opera */ 
 
     -moz-column-count: 2; /* Firefox */ 
 
     column-count: 2; 
 
     
 
     -webkit-column-gap: 20px; /* Chrome, Safari, Opera */ 
 
     -moz-column-gap: 20px; /* Firefox */ 
 
     column-gap: 20px; 
 
    }
<div> 
 
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. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. 
 
</div>

當前瀏覽器支持: http://caniuse.com/#feat=multicolumn

3

.col { 
 
    -webkit-column-count: 2; 
 
    -webkit-column-gap: 40px; 
 
    -webkit-column-rule: 1px solid #ccc; 
 

 
    -moz-column-count: 2; 
 
    -moz-column-gap: 40px; 
 
    -moz-column-rule: 1px solid #ccc; 
 

 
    column-count: 2; 
 
    column-gap: 40px; 
 
    column-rule: 1px solid #ccc; 
 
} 
 

 
.col h1, .col h2, .col h3, .col h4, .col h5, .col h6 { 
 
    -webkit-column-span:all; 
 
    -moz-column-span:all; 
 
    column-span:all; 
 
}
<div class='col'> 
 

 
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p> 
 

 
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p> 
 

 
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p> 
 

 
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p> 
 

 
</div>