Posso ter um cabeçalho de tabela HTML em duas colunas da tabela?Gosta de mesclar e centralizar no Excel?
-
14-11-2019 - |
Pergunta
Quero que um cabeçalho de tabela seja centralizado em duas colunas da tabela lado a lado.Isso é possível?
Solução
<th colspan="2">. This .</th>
Extrapolando um pouco...
<table>
<thead>
<tr>
<th>Single Column</th>
<th colspan="2">Double Column</th>
</tr>
</thead>
<tbody>
<tr>
<td>Column One</td>
<td>Column Two</td>
<td>Column Three</td>
</tr>
</tbody>
</table>
Isso deve lhe dar o suficiente para trabalhar.
Outras dicas
Se você tiver apenas 2 colunas, sugiro usar <caption>
.Caso contrário, use colspan conforme sugerido em outras respostas.
<table>
<caption>This will span all columns.</caption>
<tr><td>column one</td><td>column two</td></tr>
</table>
Claro.Consulte esse página.Você está procurando um atributo chamado colspan
para células de cabeçalhos de tabela.
Podemos fazer isso de uma maneira melhor.
<table border="1">
<tr>
<th colspan="1" scope="colgroup">Test Heading</th>
<th colspan="3" scope="colgroup">Mars</th>
<th colspan="3" scope="colgroup">Venus</th>
<th colspan="3" scope="colgroup">Test</th>
</tr>
<tr>
<th rowspan="2"></th>
<th scope="col">Produced</th>
<th scope="col">Sold</th>
<th scope="col">Sold</th>
<th scope="col">Produced</th>
<th scope="col">Sold</th>
<th scope="col">Sold</th>
<th scope="col">Test 1</th>
<th scope="col">Test 2</th>
<th scope="col">Test 3</th>
</tr>
</table>
Por favor visite Referência da tabela de w3.org se você quiser saber mais.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow