CKTIS / HTML
element HTML: colgroup
Element skupine stolpcev združi zaporedne stolpce tabele v obseg s skupno predstavitvijo.
Različica: WHATWG HTML Living Standard; index snapshot date recorded separately
Sintaksa
<table><colgroup><col></colgroup><colgroup span="2"></colgroup>…</table>colgroup je neposredni otrok table, postavljen za izbirnim caption in pred thead, tbody, tfoot ali neposrednimi vrsticami tr.
Skupina uporabi atribut span ali otroke col; ob prisotnem span je vsebinski model prazen in stolpcev ni dovoljeno dodati kot otroke.
Vrednost span pokriva od 1 do 1000 stolpcev. Brez nje je obseg vsota otrok col; prazni colgroup tedaj v model tabele prispeva privzeti obseg enega stolpca.
Združevanje ne ustvari glav podatkov, zato sta th in scope še vedno potrebna. Primer s querySelectorAll() primerja izrecni stolpec z obsegom dveh.
Primeri
<!doctype html>
<meta charset="utf-8">
<table id="report">
<caption>Measurements</caption>
<colgroup id="identity"><col></colgroup>
<colgroup id="metrics" span="2"></colgroup>
<tbody><tr><td>Item</td><td>Min</td><td>Max</td></tr></tbody>
</table>
<output id="result"></output>
<script>
const report = document.querySelector("#report");
const groups = [...report.querySelectorAll(":scope > colgroup")];
const identity = document.querySelector("#identity");
const metrics = document.querySelector("#metrics");
document.querySelector("#result").textContent = `groups=${groups.length}; afterCaption=${report.caption.nextElementSibling.tagName}; explicitCols=${identity.querySelectorAll("col").length}; metricsSpan=${metrics.span}; metricsChildren=${metrics.children.length}`;
</script>
Rezultat
groups=2; afterCaption=COLGROUP; explicitCols=1; metricsSpan=2; metricsChildren=0
Rezultat potrdi dve skupini za napisom, en izrecni stolpec in prazno skupino span; ne ocenjuje končnega sloga.