插入表格的代碼如下:
~~~
<table class="table table-bordered table-striped table-condensed">
<tr>
<td>北京</td>
<td>霧霾</td>
</tr>
<tr>
<td>深圳</td>
<td>暴雨</td>
</tr>
</table>
~~~
發現table加了個class屬性,如果只是table標簽 將不起作用。
1. table-bordered:帶圓角邊框和豎線
2. table-striped:奇偶行顏色不同
3. table-condensed:壓縮行距
除了以上另外還有其他可供選擇:
1. 如果需要表頭跟內容不一樣,可以將`<td>表頭內容</td>`換成`<th>表頭內容</th>`。
2. 如果表格內文需要換行,可以在要換行的內容后加入`<br>`,后面的內容就會跑到下一行。
3. 如果內文中有代碼,需要特別顯示,可使用:`<code>代碼</code>`。
4. 如果表格中有需要設為斜體的內容,可使用:`<I>要設為斜體的內容</I>`。
5. 如果有跨行或者跨列的單元格,可用`<th colspan="跨列數">內容</th>`或rowspan。
6. 如果要調整某一列的寬度,可使用:`<th width="寬度值或百分比">表頭內容</th>`。
| Tables | Are | Cool |
| - |:-:| -:|
| col 3 is | right-aligned | $1600 |
| col 2 is | centered | $12 |
| zebra stripes | are neat | $1 |
| Name | Academy | score |
| - | :-: | -: |
| Harry Potter | Gryffindor| 90 |
| Hermione Granger | Gryffindor | 100 |
| Draco Malfoy | Slytherin | 90 |