CSS3 multiple columns
CSS3 multi-column properties
In this chapter we will learn the following CSS3 multi-column properties:
column-count
column-gap
column-rule-style
column- rule-width
column-rule-color
column-rule
column-span
column-width
CSS3 Create multiple columns
The column-count attribute specifies the columns that need to be split number.
The following example divides the text in the <div> element into 3 columns:
Example
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <style> .newspaper { -moz-column-count:3; /* Firefox */ -webkit-column-count:3; /* Safari and Chrome */ column-count:3; } </style> </head> <body> <div class="newspaper"> “當我年輕的時候,我夢想改變這個世界;當我成熟以后,我發(fā)現(xiàn)我不能夠改變這個世界,我將目光縮短了些,決定只改變我的國家;當我進入暮年以后,我發(fā)現(xiàn)我不能夠改變我們的國家,我的最后愿望僅僅是改變一下我的家庭,但是,這也不可能。當我現(xiàn)在躺在床上,行將就木時,我突然意識到:如果一開始我僅僅去改變我自己,然后,我可能改變我的家庭;在家人的幫助和鼓勵下,我可能為國家做一些事情;然后,誰知道呢?我甚至可能改變這個世界?!?</div> </body> </html>
Run the program Try it
The gap between columns in CSS3 multiple columns
column-gap attribute specifies the gap between columns gap.
The following example specifies a gap of 40 pixels between columns:
Example
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <style> .newspaper { -moz-column-count:3; /* Firefox */ -webkit-column-count:3; /* Safari and Chrome */ column-count:3; -moz-column-gap:40px; /* Firefox */ -webkit-column-gap:40px; /* Safari and Chrome */ column-gap:40px; } </style> </head> <body> <div class="newspaper"> 累,就是常常徘徊在堅持和放棄之間,舉棋不定。累了,就休息一下;煩了,就放松一下。誰也無法去替代你的憂慮,正如無法分享你的幸福;誰也無法取舍你的選擇,正如無法左右你的腳步。一切隨意就好,希望了會失望。淡淡的來,淡淡的去,淡淡的相處,給人以寧靜,予己以清幽 </div> </body> </html>
Run the program to try it out
CSS3 column border
column-rule-style property specifies the border style between columns:
Example
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <style> .newspaper { column-count:3; column-gap:40px; column-rule-style:dotted; /* Firefox */ -moz-column-count:3; -moz-column-gap:40px; -moz-column-rule-style:dotted; /* Safari and Chrome */ -webkit-column-count:3; -webkit-column-gap:40px; -webkit-column-rule-style:dotted; } </style> </head> <body> <div class="newspaper"> 累,就是常常徘徊在堅持和放棄之間,舉棋不定。累了,就休息一下;煩了,就放松一下。誰也無法去替代你的憂慮,正如無法分享你的幸福;誰也無法取舍你的選擇,正如無法左右你的腳步。一切隨意就好,希望了會失望。淡淡的來,淡淡的去,淡淡的相處,給人以寧靜,予己以清幽</div> </body> </html>
Run the program and try it
column-rule-width attribute specifies two Column border thickness:
Example
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <style> .newspaper { column-count:3; column-gap:40px; column-rule-style:outset; column-rule-width:10px; /* Firefox */ -moz-column-count:3; -moz-column-gap:40px; -moz-column-rule-style:outset; -moz-column-rule-width:10px; /* Safari and Chrome */ -webkit-column-count:3; -webkit-column-gap:40px; -webkit-column-rule-style:outset; -webkit-column-rule-width:1px; } </style> </head> <body> <div class="newspaper"> 當我年輕的時候,我夢想改變這個世界;當我成熟以后,我發(fā)現(xiàn)我不能夠改變這個世界,我將目光縮短了些,決定只改變我的國家;當我進入暮年以后,我發(fā)現(xiàn)我不能夠改變我們的國家,我的最后愿望僅僅是改變一下我的家庭,但是,這也不可能。當我現(xiàn)在躺在床上,行將就木時,我突然意識到:如果一開始我僅僅去改變我自己,然后,我可能改變我的家庭;在家人的幫助和鼓勵下,我可能為國家做一些事情;然后,誰知道呢?我甚至可能改變這個世界。 </div> </body> </html>
Run the program to try it
The column-rule-color property specifies the border color of the two columns:
Example
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <style> .newspaper { column-count:3; column-gap:40px; column-rule-style:outset; column-rule-color:#ff0000; /* Firefox */ -moz-column-count:3; -moz-column-gap:40px; -moz-column-rule-style:outset; -moz-column-rule-color:#ff0000; /* Safari and Chrome */ -webkit-column-count:3; -webkit-column-gap:40px; -webkit-column-rule-style:outset; -webkit-column-rule-color:#ff0000; } </style> </head> <body> <div class="newspaper"> 當我年輕的時候,我夢想改變這個世界;當我成熟以后,我發(fā)現(xiàn)我不能夠改變這個世界,我將目光縮短了些,決定只改變我的國家;當我進入暮年以后,我發(fā)現(xiàn)我不能夠改變我們的國家,我的最后愿望僅僅是改變一下我的家庭,但是,這也不可能。當我現(xiàn)在躺在床上,行將就木時,我突然意識到:如果一開始我僅僅去改變我自己,然后,我可能改變我的家庭;在家人的幫助和鼓勵下,我可能為國家做一些事情;然后,誰知道呢?我甚至可能改變這個世界。 </div> </body> </html>
Run the program and try it
The column-rule attribute is the abbreviation for all attributes of column-rule-*.
The following example sets the thickness, style and color of the column border:
Example
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <style> .newspaper { -moz-column-count:3; /* Firefox */ -webkit-column-count:3; /* Safari and Chrome */ column-count:3; -moz-column-gap:40px; /* Firefox */ -webkit-column-gap:40px; /* Safari and Chrome */ column-gap:40px; -moz-column-rule:4px outset #ff00ff; /* Firefox */ -webkit-column-rule:4px outset #ff00ff; /* Safari and Chrome */ column-rule:4px outset #ff00ff; } </style> </head> <body> <div class="newspaper"> 當我年輕的時候,我夢想改變這個世界;當我成熟以后,我發(fā)現(xiàn)我不能夠改變這個世界,我將目光縮短了些,決定只改變我的國家;當我進入暮年以后,我發(fā)現(xiàn)我不能夠改變我們的國家,我的最后愿望僅僅是改變一下我的家庭,但是,這也不可能。當我現(xiàn)在躺在床上,行將就木時,我突然意識到:如果一開始我僅僅去改變我自己,然后,我可能改變我的家庭;在家人的幫助和鼓勵下,我可能為國家做一些事情;然后,誰知道呢?我甚至可能改變這個世界。 </div> </body> </html>
Run the program and try it
Specify how many columns the element spans
The following example specifies that the <h2> element spans all columns :
Example
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <style> .newspaper { column-count:3; -moz-column-count:3; /* Firefox */ -webkit-column-count:3; /* Safari and Chrome */ } h2 { column-span:all; -webkit-column-span:all; /* Safari and Chrome */ } </style> </head> <body> <div class="newspaper"> <h2>英國維斯米斯特教堂碑文</h2> 當我年輕的時候,我夢想改變這個世界;當我成熟以后,我發(fā)現(xiàn)我不能夠改變這個世界,我將目光縮短了些,決定只改變我的國家;當我進入暮年以后,我發(fā)現(xiàn)我不能夠改變我們的國家,我的最后愿望僅僅是改變一下我的家庭,但是,這也不可能。當我現(xiàn)在躺在床上,行將就木時,我突然意識到:如果一開始我僅僅去改變我自己,然后,我可能改變我的家庭;在家人的幫助和鼓勵下,我可能為國家做一些事情;然后,誰知道呢?我甚至可能改變這個世界。 </div> </body> </html>
Run the program to try
Specify the width of the column
column-width property specifies the width of the column.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <style> .newspaper { column-width:100px; -moz-column-width:100px; /* Firefox */ -webkit-column-width:100px; /* Safari and Chrome */ } </style> </head> <body> <div class="newspaper"> 當我年輕的時候,我夢想改變這個世界;當我成熟以后,我發(fā)現(xiàn)我不能夠改變這個世界,我將目光縮短了些,決定只改變我的國家;當我進入暮年以后,我發(fā)現(xiàn)我不能夠改變我們的國家,我的最后愿望僅僅是改變一下我的家庭,但是,這也不可能。當我現(xiàn)在躺在床上,行將就木時,我突然意識到:如果一開始我僅僅去改變我自己,然后,我可能改變我的家庭;在家人的幫助和鼓勵下,我可能為國家做一些事情;然后,誰知道呢?我甚至可能改變這個世界。 </div> </body> </html>
Run the program and try it
#Multi-column properties of CSS3
The following table lists all CSS3 Multi-column attributes:
Attribute | Description |
---|---|
column-count | Specify the number of columns by which elements should be split. |
column-fill | Specify how to fill the column |
column-gap | Specify the column and column The gap between |
column-rule | Abbreviation for all column-rule-* attributes |
column-rule- color | Specify the color of the border between two columns |
column-rule-style | Specify the style of the border between two columns |
column-rule-width | Specify the thickness of the border between two columns |
column-span | Specify how much the element should span Column |
column-width | Specify the width of the column |
columns | Set column-width and Abbreviation for column-count |