|
CSS 表格屬性可以幫助您極大地改善表格的外觀。 表格邊框如需在 CSS 中設(shè)置表格邊框,請(qǐng)使用 border 屬性。 下面的例子為 table、th 以及 td 設(shè)置了藍(lán)色邊框: table, th, td
{
border: 1px solid blue;
}
請(qǐng)注意,上例中的表格具有雙線條邊框。這是由于 table、th 以及 td 元素都有獨(dú)立的邊框。 如果需要把表格顯示為單線條邊框,請(qǐng)使用 border-collapse 屬性。 折疊邊框border-collapse 屬性設(shè)置是否將表格邊框折疊為單一邊框: table
{
border-collapse:collapse;
}
table,th, td
{
border: 1px solid black;
}
表格寬度和高度通過(guò) width 和 height 屬性定義表格的寬度和高度。 下面的例子將表格寬度設(shè)置為 100%,同時(shí)將 th 元素的高度設(shè)置為 50px: table
{
width:100%;
}
th
{
height:50px;
}
表格文本對(duì)齊text-align 和 vertical-align 屬性設(shè)置表格中文本的對(duì)齊方式。 text-align 屬性設(shè)置水平對(duì)齊方式,比如左對(duì)齊、右對(duì)齊或者居中: td
{
text-align:right;
}
vertical-align 屬性設(shè)置垂直對(duì)齊方式,比如頂部對(duì)齊、底部對(duì)齊或居中對(duì)齊: td
{
height:50px;
vertical-align:bottom;
}
表格顏色下面的例子設(shè)置邊框的顏色,以及 th 元素的文本和背景顏色: table, td, th
{
border:1px solid green;
}
th
{
background-color:green;
color:white;
}
CSS Table 屬性
親自試一試 - 更多實(shí)例
|
|
|