Baza znanjaCentar za ispite
HRHrvatski
Odaberi jezik13

CKTIS / HTML

HTML koncept: tables

HTML tablice opisuju podatke čije značenje proizlazi iz sjecišta redaka i stupaca, ne samo iz vizualnog poravnanja.

Verzija: WHATWG HTML Living Standard; index snapshot date recorded separately

Sintaksa

<table><caption>…</caption><thead>…</thead><tbody>…</tbody></table>

table sadrži neobavezni caption, skupine thead, tbody, tfoot i retke tr sa ćelijama th ili td; redoslijed i kontekst slijede modele.

rowspan može biti rowspan="0" i obuhvatiti preostale retke skupine; ostali rasponi i colspan pozitivni su, a ćelije se ne smiju preklapati.

Jednostavna zaglavlja koriste scope s row ili col; složene tablice povezuju headers s id. Tablica nije za raspored stranice.

Primjer čita caption, zbirke rows i tBodies, cellIndex te izričite headers i scope.

Primjeri

<!doctype html>
<meta charset="utf-8">
<table id="prices">
  <caption>Prices</caption>
  <thead><tr><th id="product" scope="col">Product</th><th id="amount" scope="col">Amount</th></tr></thead>
  <tbody><tr><th id="widget" scope="row">Widget</th><td id="price" headers="widget amount">9</td></tr></tbody>
</table>
<output id="result"></output>
<script>
const table = document.querySelector("#prices");
const cell = document.querySelector("#price");
result.textContent = `caption=${table.caption.textContent}; rows=${table.rows.length}; bodies=${table.tBodies.length}; cellIndex=${cell.cellIndex}; headers=${cell.headers}; rowScope=${widget.scope}`;
</script>

Rezultat

caption=Prices; rows=2; bodies=1; cellIndex=1; headers=widget amount; rowScope=row

Rezultat potvrđuje DOM mrežu i autorske veze; ne simulira čitač zaslona ni složen algoritam zaglavlja.

Izvori