標籤:
CSS表格與列表
學習要點:
1.表格樣式
2.列表樣式
3.其他功能
一.表格樣式
表格有五種專屬樣式,樣式表如下:
屬性 值 說明 CSS版本
border-collapse 邊框樣式 相鄰儲存格的邊框樣式 2
border-spacing 長度值 相鄰儲存格邊框的間距 2
caption-side 位置名稱 表格標題的位置 2
empty-cells 顯示值 空儲存格是否顯示邊框 2
table-layout 配置樣式 指定表格的配置樣式 2
border-collapse儲存格相鄰的邊框被合并
值 說明 CSS版本
separate 預設值,儲存格邊框獨立 2
collapse 儲存格相鄰邊框被合并 2
table{ border-collapse: collapse;}<table border="1"> <tr> <th>1</th> <th>2</th> <th>3</th> </tr> <tr> <td>4</td> <td>5</td> <td>6</td> </tr></table>
border-spacing設定儲存格之間的間距
解釋:border-collapse:separate;(預設)的狀態下才有效。因為要設定間距,不能合并。
值 說明 CSS版本
長度值 0表示間距,其他使用CSS長度值 2
table{ border-spacing: 10px;}<table border="1"> <tr> <th>1</th> <th>2</th> <th>3</th> </tr> <tr> <td>4</td> <td>5</td> <td>6</td> </tr></table>
caption-side設定表格標題位置
值 說明 CSS版本
top 預設值,標題在上方 2
bottom 標題在下方 2
table{ border-spacing: 10px; caption-side: bottom;}<table border="1"> <caption>這是一張表</caption> <tr> <th>1</th> <th>2</th> <th>3</th> </tr> <tr> <td>4</td> <td>5</td> <td>6</td> </tr></table>
empty-cells儲存格內容為空白時隱藏邊框
值 說明 CSS版本
sho 預設值,顯示邊框 2
hide 不顯示邊框 2
table{ border-spacing: 10px; empty-cells: hide;}<table border="1"> <tr> <th>1</th> <th>2</th> <th>3</th> </tr> <tr> <td>4</td> <td>5</td> <td></td> </tr></table>
table-layout內容過長後,不會展開整個儲存格
注意:要設定了表格的寬度和高度後有用
值 說明 CSS版本
auto 預設值,內容過長時,展開整個儲存格 2
fixed 內容過長時,不展開整個儲存格 2
table{ width: 400px; height: 300px; text-align: center; table-layout: fixed;}<table border="1"> <tr> <th>1</th> <th>2</th> <th>3</th> </tr> <tr> <td>4這個表格的內容加長了</td> <td>5</td> <td>6</td> </tr></table>
二.列表樣式
列表有四種專屬樣式,樣式表如下:
屬性 值 說明 CSS版本
list-style-type 類型值 列表中的標記類型 1/2
list-style-image none或url 映像作為列表標記 1
list-style-position 位置值 排列的相對位置 1
list-style 簡寫屬性 列表的簡寫形式 1
list-style-type列表首碼的標記類型
值 說明 CSS版本
none 沒有標記 1
disc 實心圓 1
circle 空心圓 1
square 實心方塊 1
decimal 阿拉伯數字 1
lower-roman 小寫羅馬數字 1
upper-roman 大寫羅馬數字 1
lower-alpha 小寫英文字母 1
upper-roman 大寫英文字母 1
ul{ list-style-type: none;}<ul> <li>列表1</li> <li>列表2</li> <li>列表3</li> <li>列表4</li></ul>
第七十五節,CSS表格與列表