HTML colspan-Attribut
Das HTML colspan-Attribut gibt an, über wie viele Spalten eine Tabellenzelle erstrecken soll. Der Wert muss eine positive Ganzzahl sein. Dieses Attribut ermöglicht es einer einzelnen Tabellenzelle, die Breite von mehr als einer Spalte oder Zelle zu umfassen. Es hat die gleiche Funktionalität wie „Zellen zusammenführen“ in Excel.
Sie können das Attribut colspan auf die <td> und <th> Elemente anwenden.
Wenn das Attribut colspan im <td>-Tag verwendet wird, bestimmt es die Anzahl der Standardzellen, die es umfassen soll. Bei Verwendung im <th>-Tag gibt das Attribut colspan die Anzahl der Kopfzellen an, die es umfassen soll.
Syntax
Syntax des HTML colspan-Attributs
<tag colspan="value"></tag>Beispiel für die Verwendung des HTML colspan-Attributs im <td>-Element:
Beispiel für die Verwendung des HTML colspan-Attributs im <td>-Element
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<table border="1">
<tr>
<th>Month</th>
<th>Salary</th>
</tr>
<tr>
<td>March</td>
<td>$100</td>
</tr>
<tr>
<td>April</td>
<td>$150</td>
</tr>
<tr>
<td colspan="2">Total: $250</td>
</tr>
</table>
</body>
</html>Beispiel für die Verwendung des HTML colspan-Attributs im <th>-Element:
Beispiel für die Verwendung des HTML colspan-Attributs im <th>-Element
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<table border="1">
<tr>
<th colspan="2">Month and Date</th>
</tr>
<tr>
<td>January</td>
<td>15</td>
</tr>
<tr>
<td>February</td>
<td>23</td>
</tr>
</table>
</body>
</html>Practice
Was ist der Hauptzweck des HTML colspan-Attributs?