Le Tutoriel de HTML Col, Colgroup
View more Tutorials:
L'étiquette <col> et <colgroup> đ représente pour une colonne et un groupe de colonnes d'un tableau.
<colgroup> est sous- étiquette de <table>, Il est situé après <caption>, et avant <thead>, <tbody>, <tfoot>, <tr>. Une table peut avoir 0 ou plus sous- étiquettes <colgroup> et chaque <colgroup> a 0 ou plus sous- étiquettes <col>.
Si <colgroup> ne contient pas sous- étiquette <col> :
<colgroup span = "<number>"> </colgroup>
Il est équivalent à :
<colgroup> <col span = "<number>" /> </colgroup>
Exemple :
simple-colgroup-example.html
<!DOCTYPE html> <html> <head> <title>Table align</title> <meta charset="UTF-8"/> <style> table, th, td { border: 1px solid black; } th, td { padding: 10px; } </style> </head> <body> <h2>HTML colgroup</h2> <table> <colgroup> <col span ="3" style="background-color:lightblue"> </colgroup> <tr> <th>No</th> <th>ISBN</th> <th>Title</th> <th>Price</th> <th>Description</th> </tr> <tr> <td>1</td> <td>3476896</td> <td>My first HTML</td> <td>$53</td> <td>..</td> </tr> <tr> <td>2</td> <td>5869207</td> <td>My first CSS</td> <td>$49</td> <td>..</td> </tr> </table> </body> </html>
Exemple, un tableau peut comprendre plusieur <colgroup> :
colgroup-example.html
<!DOCTYPE html> <html> <head> <title>HTML Colgroup, Col</title> <meta charset="UTF-8"/> <style> table, th, td { border: 1px solid black; } th, td { padding: 10px; } </style> </head> <body> <h2>HTML Colgroup, Col</h2> <table> <colgroup> <col style="background-color:lightgreen;width: 50px;"/> </colgroup> <colgroup style="background-color:yellow;"> <col span="2"/> <col style="width: 90px;"/> </colgroup> <tr> <th>No</th> <th>ISBN</th> <th>Title</th> <th>Price</th> <th>Description</th> </tr> <tr> <td>1</td> <td>3476896</td> <td>My first HTML</td> <td>$53</td> <td>..</td> </tr> <tr> <td>2</td> <td>5869207</td> <td>My first CSS</td> <td>$49</td> <td>..</td> </tr> </table> </body> </html>
Seules quelques propriétés (property) CSS peuvent s'appliquer à <colgroup>, <col>.
CSS border
CSS border ne fonctionnera qu'avec un tableau de réduction (Collapsing Table). Voir l'exemple suivant
CSS background-*
CSS background-* de <colgroup>, <col> ne fonctionne que dans les endroits où une ligne (row) ou une cellule de table est transparente.
CSS width
Configurez la largeur de <col>, <colgroup>.
CSS {visibility: collapse}
Vous pouvez appliquer CSS visibility au <colgroup>, <col> mais seulement avec la valeur {visibility:collapse}. Les autres valeurs sont invalides et sont ignorées, ou traitées comme {visibility:visible}.
CSS border
CSS border qui applique à <col>, <colgroup> ne fonctionne qu'avec un tableau de réduction (Collapsing Table).
colgroup-border-example.html
<!DOCTYPE html> <html> <head> <title>HTML Colgroup, Col</title> <meta charset="UTF-8"/> <style> table, th, td { border: 1px solid black; border-collapse: collapse; } th, td { padding: 10px; } </style> </head> <body> <h2>HTML Colgroup, Col</h2> <p style="color:blue; font-style:italic;"> CSS border for COL, COLGROUP works only in Collasing Table. </p> <table> <colgroup> <col style="background-color:lightgreen;width: 50px;"/> </colgroup> <colgroup style="background-color:yellow; border: 3px solid red;"> <col span="2"/> <col style="width: 90px;"/> </colgroup> <tr> <th>No</th> <th>ISBN</th> <th>Title</th> <th>Price</th> <th>Description</th> </tr> <tr> <td>1</td> <td>3476896</td> <td>My first HTML</td> <td>$53</td> <td>..</td> </tr> <tr> <td>2</td> <td>5869207</td> <td>My first CSS</td> <td>$49</td> <td>..</td> </tr> </table> </body> </html>