¿Puedo tener un encabezado de tabla HTML sobre dos columnas de tabla?¿Te gusta fusionar y centrar en Excel?
-
14-11-2019 - |
Pregunta
Quiero que un encabezado de tabla esté centrado sobre dos columnas de tabla una al lado de la otra.es posible?
Solución
<th colspan="2">. This .</th>
para extrapolar un poco ...
<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>
que debería darle lo suficiente para trabajar desde.
Otros consejos
Si solo tiene 2 columnas, sugeriría usar <caption>
.De lo contrario, use Colspan como se sugiere en otras respuestas.
<table>
<caption>This will span all columns.</caption>
<tr><td>column one</td><td>column two</td></tr>
</table>
Por supuesto.Por favor refiérase a este página.Estás buscando un atributo llamado colspan
para celdas de encabezados de tabla.
Podemos hacerlo de mejor manera.
<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>
Visite mesa de tabla de w3.org si quieres saber más.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow