Tag HTML <td>
Exemplo
Uma tabela HTML simples, com duas linhas e quatro células de tabela:
<table>
<tr>
<td>Cell A</td>
<td>Cell B</td>
</tr>
<tr>
<td>Cell C</td>
<td>Cell D</td>
</tr>
</table>
Mais exemplos de "Experimente você mesmo" abaixo.
Definição e uso
A <td>
tag define uma célula de dados padrão em uma tabela HTML.
Uma tabela HTML tem dois tipos de células:
- Células de cabeçalho - contém informações de cabeçalho (criadas com o elemento <th> )
- Células de dados - contém dados (criados com o
<td>
elemento)
O texto nos <td>
elementos é regular e alinhado à esquerda por padrão.
O texto nos elementos <th> está em negrito e centralizado por padrão.
Suporte ao navegador
Element | |||||
---|---|---|---|---|---|
<td> | Yes | Yes | Yes | Yes | Yes |
Atributos
Attribute | Value | Description |
---|---|---|
colspan | number | Specifies the number of columns a cell should span |
headers | header_id | Specifies one or more header cells a cell is related to |
rowspan | number | Sets the number of rows a cell should span |
Atributos Globais
A <td>
tag também suporta os Atributos Globais em HTML .
Atributos do evento
A <td>
tag também suporta os atributos de evento em HTML .
Mais exemplos
Exemplo
Como alinhar conteúdo dentro de <td> (com CSS):
<table style="width:100%">
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td
style="text-align:right">$100</td>
</tr>
<tr>
<td>February</td>
<td
style="text-align:right">$80</td>
</tr>
</table>
Exemplo
Como adicionar cor de fundo à célula da tabela (com CSS):
<table>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td
style="background-color:#FF0000">January</td>
<td
style="background-color:#00FF00">$100</td>
</tr>
</table>
Exemplo
Como definir a altura de uma célula da tabela (com CSS):
<table>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td
style="height:100px">January</td>
<td
style="height:100px">$100</td>
</tr>
</table>
Exemplo
Como especificar sem quebra de palavras na célula da tabela (com CSS):
<table>
<tr>
<th>Poem</th>
</tr>
<tr>
<td
style="white-space:nowrap">Never increase, beyond what is necessary, the
number of entities required to explain anything</td>
</tr>
</table>
Exemplo
Como alinhar conteúdo verticalmente dentro de <td> (com CSS):
<table style="width:50%;">
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr style="height:100px">
<td
style="vertical-align:bottom">January</td>
<td
style="vertical-align:bottom">$100</td>
</tr>
</table>
Exemplo
Como definir a largura de uma célula da tabela (com CSS):
<table style="width:100%">
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td style="width:70%">January</td>
<td style="width:30%">$100</td>
</tr>
</table>
Exemplo
Como criar cabeçalhos de tabela:
<table>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
</tr>
<tr>
<td>John Doe</td>
<td>[email protected]</td>
<td>123-45-678</td>
</tr>
</table>
Exemplo
Como criar uma tabela com uma legenda:
<table>
<caption>Monthly savings</caption>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</table>
Exemplo
Como definir células de tabela que abrangem mais de uma linha ou uma coluna:
<table>
<tr>
<th>Name</th>
<th>Email</th>
<th colspan="2">Phone</th>
</tr>
<tr>
<td>John Doe</td>
<td>[email protected]</td>
<td>123-45-678</td>
<td>212-00-546</td>
</tr>
</table>
Páginas relacionadas
Tutorial HTML: Tabelas HTML
Referência HTML DOM: objeto TableData
Tutorial CSS: Estilizando Tabelas
Configurações padrão de CSS
A maioria dos navegadores exibirá o <td>
elemento com os seguintes valores padrão:
td {
display: table-cell;
vertical-align: inherit;
}