- left
- right
- both
left 使浮動元素不出現在右邊,相對的 , right 使浮動元素不出現在左邊, both 則是兩邊都不出現。
因為浮動元素有可能會出現在區塊元素 (block element) 的旁邊,例如
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | p { width : 100px ; height : 100px ; border : thin solid black ; } h 1 { border : thin solid black ; } . blue { color : white ; background : blue ; float : left ; } . red { color : white ; background : red ; float : right ; } /* 《程式語言教學誌》的範例程式 檔名:visual02.css 功能:示範 CSS 2.1 樣式表的使用 作者:張凱慶 時間:西元 2011 年 7 月 */ |
我們以下面的 HTML 文件載入
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | < html > < head > < title >網頁標題</ title > < link rel = "stylesheet" type = "text/css" href = "visual02.css" > </ head > < body > < p class = "blue" >You ever have that feeling where you're not sure if you're awake or still dreaming?</ p > < h1 >A prison for your mind.</ h1 > < p class = "red" >Free your mind.</ p > </ body > </ html > <!-- 《程式語言教學誌》的範例程式 檔名:visual02.html 功能:示範 CSS 2.1 樣式表的使用 作者:張凱慶 時間:西元 2011 年 7 月 --> |
瀏覽器 (broswer) 開啟如下

如果我們要抑制這樣的情況出現,可以將 <h1> 設定成 clear:both ,或是將其放在另一個類別選取器 (class selector) 裡,例如
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | p { width : 100px ; height : 100px ; border : thin solid black ; } h 1 { border : thin solid black ; } . blue { color : white ; background : blue ; float : left ; } . red { color : white ; background : red ; float : right ; } .exampleleft { float : right ; clear : left ; } /* 《程式語言教學誌》的範例程式 檔名:visual03.css 功能:示範 CSS 2.1 樣式表的使用 作者:張凱慶 時間:西元 2011 年 7 月 */ |
我們以下面的 HTML 文件載入
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | < html > < head > < title >網頁標題</ title > < link rel = "stylesheet" type = "text/css" href = "visual03.css" > </ head > < body > < p class = "blue" >You ever have that feeling where you're not sure if you're awake or still dreaming?</ p > < h1 class = "exampleboth" >A prison for your mind.</ h1 > < p class = "red" >Free your mind.</ p > </ body > </ html > <!-- 《程式語言:教學誌》的範例程式 檔名:visual03.html 功能:示範 CSS 2.1 樣式表的使用 作者:張凱慶 時間:西元 2011 年 7 月 --> |
結果如下

中英文術語對照 | |
---|---|
性質 | property |
元素 | element |
關鍵字 | keyword |
區塊元素 | block element |
瀏覽器 | broswer |
類別選取器 | class selector |
您可以繼續參考
JavaScript 範例
定位相關
相關目錄
CSS 2.1 快速導覽
HTML, CSS 教材
首頁
參考資料
http://www.w3.org/TR/CSS21/visuren.html
https://developer.mozilla.org/en/CSS/clear
沒有留言:
張貼留言