CSS3 多列
CSS3 多列屬性
本章節(jié)我們將學(xué)習(xí)以下幾個 CSS3 的多列屬性:
column-count
column-gap
column-rule-style
column-rule-width
column-rule-color
column-rule
column-span
column-width
CSS3 創(chuàng)建多列
column-count?屬性指定了需要分割的列數(shù)。
以下實例將 <div> 元素中的文本分為 3 列:
實例
<!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"> “當(dāng)我年輕的時候,我夢想改變這個世界;當(dāng)我成熟以后,我發(fā)現(xiàn)我不能夠改變這個世界,我將目光縮短了些,決定只改變我的國家;當(dāng)我進入暮年以后,我發(fā)現(xiàn)我不能夠改變我們的國家,我的最后愿望僅僅是改變一下我的家庭,但是,這也不可能。當(dāng)我現(xiàn)在躺在床上,行將就木時,我突然意識到:如果一開始我僅僅去改變我自己,然后,我可能改變我的家庭;在家人的幫助和鼓勵下,我可能為國家做一些事情;然后,誰知道呢?我甚至可能改變這個世界?!?</div> </body> </html>
運行程序嘗試一下
CSS3 多列中列與列間的間隙
column-gap?屬性指定了列與列間的間隙。
以下實例指定了列與列間的間隙為 40 像素:
實例
<!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>
運行程序嘗試一下
CSS3 列邊框
column-rule-style?屬性指定了列與列間的邊框樣式:
實例
<!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>
運行程序嘗試一下
column-rule-width?屬性指定了兩列的邊框厚度:
實例
<!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"> 當(dāng)我年輕的時候,我夢想改變這個世界;當(dāng)我成熟以后,我發(fā)現(xiàn)我不能夠改變這個世界,我將目光縮短了些,決定只改變我的國家;當(dāng)我進入暮年以后,我發(fā)現(xiàn)我不能夠改變我們的國家,我的最后愿望僅僅是改變一下我的家庭,但是,這也不可能。當(dāng)我現(xiàn)在躺在床上,行將就木時,我突然意識到:如果一開始我僅僅去改變我自己,然后,我可能改變我的家庭;在家人的幫助和鼓勵下,我可能為國家做一些事情;然后,誰知道呢?我甚至可能改變這個世界。 </div> </body> </html>
運行程序嘗試一下
column-rule-color?屬性指定了兩列的邊框顏色:
實例
<!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"> 當(dāng)我年輕的時候,我夢想改變這個世界;當(dāng)我成熟以后,我發(fā)現(xiàn)我不能夠改變這個世界,我將目光縮短了些,決定只改變我的國家;當(dāng)我進入暮年以后,我發(fā)現(xiàn)我不能夠改變我們的國家,我的最后愿望僅僅是改變一下我的家庭,但是,這也不可能。當(dāng)我現(xiàn)在躺在床上,行將就木時,我突然意識到:如果一開始我僅僅去改變我自己,然后,我可能改變我的家庭;在家人的幫助和鼓勵下,我可能為國家做一些事情;然后,誰知道呢?我甚至可能改變這個世界。 </div> </body> </html>
運行程序嘗試一下
column-rule?屬性是 column-rule-* 所有屬性的簡寫。
以下實例設(shè)置了列直接的邊框的厚度,樣式及顏色:
實例
<!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"> 當(dāng)我年輕的時候,我夢想改變這個世界;當(dāng)我成熟以后,我發(fā)現(xiàn)我不能夠改變這個世界,我將目光縮短了些,決定只改變我的國家;當(dāng)我進入暮年以后,我發(fā)現(xiàn)我不能夠改變我們的國家,我的最后愿望僅僅是改變一下我的家庭,但是,這也不可能。當(dāng)我現(xiàn)在躺在床上,行將就木時,我突然意識到:如果一開始我僅僅去改變我自己,然后,我可能改變我的家庭;在家人的幫助和鼓勵下,我可能為國家做一些事情;然后,誰知道呢?我甚至可能改變這個世界。 </div> </body> </html>
運行程序嘗試一下
指定元素跨越多少列
以下實例指定 <h2> 元素跨越所有列:
實例
<!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> 當(dāng)我年輕的時候,我夢想改變這個世界;當(dāng)我成熟以后,我發(fā)現(xiàn)我不能夠改變這個世界,我將目光縮短了些,決定只改變我的國家;當(dāng)我進入暮年以后,我發(fā)現(xiàn)我不能夠改變我們的國家,我的最后愿望僅僅是改變一下我的家庭,但是,這也不可能。當(dāng)我現(xiàn)在躺在床上,行將就木時,我突然意識到:如果一開始我僅僅去改變我自己,然后,我可能改變我的家庭;在家人的幫助和鼓勵下,我可能為國家做一些事情;然后,誰知道呢?我甚至可能改變這個世界。 </div> </body> </html>
運行程序嘗試一下
指定列的寬度
column-width?屬性指定了列的寬度。
<!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"> 當(dāng)我年輕的時候,我夢想改變這個世界;當(dāng)我成熟以后,我發(fā)現(xiàn)我不能夠改變這個世界,我將目光縮短了些,決定只改變我的國家;當(dāng)我進入暮年以后,我發(fā)現(xiàn)我不能夠改變我們的國家,我的最后愿望僅僅是改變一下我的家庭,但是,這也不可能。當(dāng)我現(xiàn)在躺在床上,行將就木時,我突然意識到:如果一開始我僅僅去改變我自己,然后,我可能改變我的家庭;在家人的幫助和鼓勵下,我可能為國家做一些事情;然后,誰知道呢?我甚至可能改變這個世界。 </div> </body> </html>
運行程序嘗試一下
CSS3 的多列屬性
下表列出了所有 CSS3 的多列屬性:
屬性 | 描述 |
---|---|
column-count | 指定元素應(yīng)該被分割的列數(shù)。 |
column-fill | 指定如何填充列 |
column-gap | 指定列與列之間的間隙 |
column-rule | 所有 column-rule-* 屬性的簡寫 |
column-rule-color | 指定兩列間邊框的顏色 |
column-rule-style | 指定兩列間邊框的樣式 |
column-rule-width | 指定兩列間邊框的厚度 |
column-span | 指定元素要跨越多少列 |
column-width | 指定列的寬度 |
columns | 設(shè)置 column-width 和 column-count 的簡寫 |