Advent

Day 16: Table 🎶

A table is used to display tabular data.

The example component is visible below.


Christmas carols origins
Song 🎶Country 🗺️
Silent Night🇦🇹 Austria
Santa Claus Is Coming To Town🇺🇸 United States of America
Hark! The Herald Angels Sing🏴󠁧󠁢󠁥󠁮󠁧󠁿 England
Deck The Halls🏴󠁧󠁢󠁷󠁬󠁳󠁿 Wales
Jingle Bells🇺🇸 United States of America
O Tannenbaum🇩🇪 Germany

A few notes about this table component:

  • CSS Variables are used for colors,
  • the .advent-table tr:only-child selector is used to adding a thicker border to distinguish table head,
  • the .advent-table tr:not(:only-child):nth-child(even) selector is used to apply background color to every even sibling that is not the only one (see my article about “enabling” selectors).

The code:

<div class="advent-table">
  <table>
    <caption>Christmas carols origins</caption>
    <thead>
      <tr>
        <th>Song 🎶</th>
        <th>Country 🗺️</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Silent Night</td>
        <td>🇦🇹 Austria</td>
      </tr>
      <tr>
        <td>Santa Claus Is Coming To Town</td>
        <td>🇺🇸 United States of America</td>
      </tr>
      <tr>
        <td>Hark! The Herald Angels Sing</td>
        <td>🏴󠁧󠁢󠁥󠁮󠁧󠁿 England</td>
      </tr>
      <tr>
        <td>Deck The Halls</td>
        <td>🏴󠁧󠁢󠁷󠁬󠁳󠁿 Wales</td>
      </tr>
      <tr>
        <td>Jingle Bells</td>
        <td>🇺🇸 United States of America</td>
      </tr>
      <tr>
        <td>O Tannenbaum</td>
        <td>🇩🇪 Germany</td>
      </tr>
    </tbody>
  </table>
</div>
.advent-table {
  --color-xmas-alpha: #f7efef;
  --color-xmas-beta: #d72621;
  --color-xmas-gamma: #639565;
  --color-xmas-delta: #fff;
  overflow: auto;
}

.advent-table table {
  border-collapse: collapse;
  background-color: var(--color-xmas-delta);
  color: var(--color-xmas-gamma);
  min-width: calc(100% - 2px);
}

.advent-table th,
.advent-table td {
  border: 1px solid var(--color-xmas-beta);
  padding: .5em;
}

.advent-table tr:only-child {
  border-bottom: .2em solid var(--color-xmas-beta);
}

.advent-table tr:not(:only-child):nth-child(even) {
  background-color: var(--color-xmas-alpha);
}

.advent-table caption,
.advent-table th {
  font-weight: bold;
}

Advent of UI components 🎄

Check other UI components.

Day 24: Details 🎹

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 24: Details.

Day 23: Radio button 📱

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 23: Radio button.

Day 22: Checkbox 🧦

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 22: Checkbox.

Day 21: Notification 🤫

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 21: Notification.

Day 20: Code block 💻

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 20: Code block.

Day 19: Pagination 📖

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 19: Pagination.

Day 18: Social share 🔗

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 18: Social share.

Day 17: Card 🎴

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 17: Card.

Day 15: Breadcrumb 🍞

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 15: Breadcrumb.

Day 14: Blockquote 💬

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 14: Blockquote.

Day 13: List 🗒️

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 13: List.

Day 12: Figure 🖼️

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 12: Figure.

Day 11: Video embed 📺

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 11: Video embed.

Day 10: Footer 👇

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 10: Footer.

Day 9: Header ☝️

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 9: Header.

Day 8: Hero 🦸‍♂️

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 8: Hero.

Day 7: Intro 💬

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 7: Intro.

Day 6: Horizontal rule 〰️

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 6: Horizontal rule.

Day 5: Split 💔

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 5: Split.

Day 4: Banner 🚩

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 4: Banner.

Day 3: Gallery 🍿

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 3: Gallery.

Day 2: Tag 🎁

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 2: Tag.

Day 1: Button 🎅

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 1: Button.