Tag HTML <td>
- Pagina precedente <tbody>
- Pagina successiva <template>
Definizione e uso
<td>
Il tag definisce la cellula dati standard nella tabella HTML.
HTML ha due tipi di celle di tabella:
- Cellula di intestazione - contiene informazioni di intestazione (usando <th> creazione dell'elemento)
- Cellula dati - contiene dati (usando
<td>
creazione dell'elemento)
Per impostazione predefinita,<td>
Il testo nell'elemento è normale e allineato a sinistra.
Il testo nell'elemento <th> è predefinito in grassetto e centrato.
Vedi anche:
Corso HTML:Tabella HTML
Manuale di riferimento HTML DOM:Oggetto TableData
Corso CSS:Impostare lo stile della tabella
Esempio
Esempio 1
Una tabella HTML semplice, con due righe e quattro celle di tabella:
<table> <tr> <td>Cellula A</td> <td>Cellula B</td> </tr> <tr> <td>Cellula C</td> <td>Cellula D</td> </tr> </table>
Esempio 2
Come allineare <td>
中的内容(使用 CSS):
<table style="width:100%"> <tr> <th>月份</th> <th>储蓄</th> </tr> <tr> <td>一月</td> <td style="text-align:right">¥3400</td> </tr> <tr> <td>二月</td> <td style="text-align:right">¥4500</td> </tr> </table>
Esempio 3
Come aggiungere il colore di sfondo alle celle della tabella (usando CSS):
<table> <tr> <th>月份</th> <th>储蓄</th> </tr> <tr> <td style="background-color:#FF0000">一月</td> <td style="background-color:#00FF00">¥3400</td> </tr> </table>
例子 4
如何设置表格单元格的高度(使用 CSS):
<table> <tr> <th>月份</th> <th>储蓄</th> </tr> <tr> <td style="height:100px">一月</td> <td style="height:100px">¥3400</td> </tr> </table>
例子 5
如何在表格单元格中规定不换行(使用 CSS):
<table> <tr> <th>诗</th> </tr> <tr> <td style="white-space:nowrap">朝辞白帝彩云间,千里江陵一日还。两岸猿声啼不住,轻舟已过万重山。</td> </tr> </table>
例子 6
如何垂直对齐 <td>
中的内容(使用 CSS):
<table style="width:50%;"> <tr> <th>月份</th> <th>储蓄</th> </tr> <tr style="height:100px"> <td style="vertical-align:bottom">一月</td> <td style="vertical-align:bottom">¥3400</td> </tr> </table>
例子 7
如何设置表格单元格的宽度(使用 CSS):
<table style="width:100%"> <tr> <th>月份</th> <th>储蓄</th> </tr> <tr> <td style="width:70%">一月</td> <td style="width:30%">¥3400</td> </tr> </table>
例子 8
如何创建表格标题:
<table> <tr> <th>姓名</th> <th>电邮</th> <th>电话</th> </tr> <tr> <td>Bill Gates</td> <td>bill.gates@example.com</td> <td>138-1234-5678</td> </tr> </table>
例子 9
如何创建带标题的表格:
<table> <caption>月份ly savings</caption> <tr> <th>月份</th> <th>储蓄</th> </tr> <tr> <td>一月</td> <td>¥3400</td> </tr> <tr> <td>二月</td> <td>¥4500</td> </tr> </table>
例子 10
如何定义跨越多行或多列的表格单元格:
<table> <tr> <th>姓名</th> <th>电邮</th> <th colspan="2">电话</th> </tr> <tr> <td>Bill Gates</td> <td>bill.gates@example.com</td> <td>138-1234-5678</td> <td>186-2345-6789</td> </tr> </table>
Proprietà
Proprietà | Valore | Descrizione |
---|---|---|
colspan | Numero | Specificare il numero di colonne che la cella deve coprire. |
headers | header_id | Specificare una o più celle di intestazione correlate alla cella. |
rowspan | Numero | Impostare il numero di righe che la cella deve coprire. |
Proprietà globali
<td>
Il tag supporta anche Proprietà globali in HTML.
proprietà di evento
<td>
Il tag supporta anche Proprietà di evento in HTML.
Impostazioni CSS predefinite
La maggior parte dei browser utilizzerà i seguenti valori predefiniti per la visualizzazione <td>
Elemento:
td { display: table-cell; vertical-align: inherit; }
Supporto browser
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Supporto | Supporto | Supporto | Supporto | Supporto |
- Pagina precedente <tbody>
- Pagina successiva <template>