1. 程式人生 > >08:CSS設定表格樣式

08:CSS設定表格樣式

1.一個簡單的表格
table.html

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>表格樣式</title>
    <link href="box.css" type="text/css" rel="stylesheet">
</head>
<body>
  <center>
  <table class="class">
      <caption
>
課程表</caption> <tr> <th>星期\課程</th> <th>星期一</th> <th>星期二</th> <th>星期三</th> <th>星期四</th> <th>星期五</th> </tr> <tr> <th
>
1-2節</th> <td>數學</td> <td>語文</td> <td>化學</td> <td>英語</td> <td>英語</td> </tr> <tr> <th>3-4節</th> <td>英語</td>
<td>物理</td> <td>化學</td> <td>英語</td> <td>體育</td> </tr> <tr> <th>5-6節</th> <td>數學</td> <td>物理</td> <td>體育</td> <td>化學</td> <td>美術</td> </tr> <tr> <th>7-8節</th> <td>數學</td> <td>美術</td> <td>化學</td> <td>英語</td> <td>體育</td> </tr> <tr> <th>9-10節</th> <td>生物</td> <td>美術</td> <td>生物</td> <td>英語</td> <td>物理</td> </tr> </table> </center> </body> </html>

table.css

table,td,th{
    border:1px solid #aaa;
    font-size: 23px;

}

2.邊框合併:boder-collapse
屬性值:
separate;(分開,預設)
collapse;(合併)

table.css

table,td,th{
    border:1px solid #aaa;
    font-size: 23px;
    border-collapse:collapse;
}

3.邊框間距border-spacing(前提是:border-collapse:separate;)

table.css

table,td,th{
    border:1px solid #aaa;
    font-size: 23px;
    border-collapse:separate;
    border-spacing: 45px;
}

4.設定表格標題的位置caption-side
屬性值:
top;//預設
bottom;
left;
right;

table.css

table,td,th{
    border:1px solid #aaa;
    font-size: 23px;
    border-collapse:separate;
    border-spacing: 45px;
    caption-side:bottom;
}

5.當單元格物件寬度超過單元格所定義的寬度時,可用table-layout:fixed保持表格寬度不被改變
屬性值:auto(預設)
fixed(寬度固定)
table.css

table,td,th{
    border:1px solid #aaa;
    font-size: 23px;
    border-collapse:separate;
    border-spacing: 5px;
    table-layout: fixed;
    caption-side:top;

}
19:30 2018/8/17/週五