Sobes.tech
Intern

Kāda ir tabulas struktūra HTML?

sobes.tech AI

Atbilde no AI

HTML tabulas struktūra tiek definēta ar vairākām elementiem:

  • <table>: Tabulas ietvars.
  • <caption>: Neobligāts virsraksts tabulai.
  • <colgroup> un <col>: Neobligāti elementi kolonu grupēšanai un stilu piemērošanai.
  • <thead>: Kolonnu virsrakstu sadaļa.
  • <tbody>: Galvenā satura sadaļa.
  • <tfoot>: Apakšsadaļa tabulai.
  • <tr>: Tabulas rinda.
  • <th>: Virsraksta šūna rindā.
  • <td>: Datu šūna rindā.

Elementi <thead>, <tbody> un <tfoot> palīdz grupēt rindas pēc nozīmes un var tikt izmantoti pārlūkprogrammās, lai optimizētu lielu tabulu attēlošanu. Šajās sadaļās atrodas <tr> elementi. <tr> iekšpusē ir <th> (parasti <thead>-ā, dažreiz <tbody> vai <tfoot>-ā) vai <td> ( <tbody> un <tfoot>-ā, dažreiz <thead>-ā).

Pamatstruktūras piemērs:

<table>
  <caption>
    Preču saraksts
  </caption>
  <thead>
    <tr>
      <th>Nosaukums</th>
      <th>Cena</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Prece 1</td>
      <td>100</td>
    </tr>
    <tr>
      <td>Prece 2</td>
      <td>150</td>
    </tr>
  </tbody>
  <tfoot>
    <tr>
      <td colspan="2">Kopā: 250</td>
    </tr>
  </tfoot>
</table>