tables & lists

responsive tables with axis-swap for mobile (and pseudo-headers instead of th)

Entry’s title 1st col 2nd col 3rd col 4th col
Renault Twingo 2023 X7868-9448-00928 XAUZZ17­449930020 XAG-ZZ0­440030029 X-9289 4432 8820
Ford Focus Tournier 1.0eco 5-Gang @7868-9288-00998 ZZ17829­93WAU0000 PSA-DL0­018810089 ZUR-4289­62328890
Ferrari Enzo 612 #7868-9288-00998 WAUZZ178­29930000 VAG-ZZ00­20030089 L-9289 5232 8890
Brabus GT950 WAUZZ17­829930000 #7868-9288-00998 L-9289 5232 8890 VAG-ZZ0­020030089

There are dozens of methods to display tabular content responsively, this one is relatively simple and based on plain html table markup. It solves the problem of scrolling away the column headers – without scripting.

The labels for mobile (single column) are created as :before pseudo element, the disadvantage here is: content is in the stylesheet, which screen readers do not like. But in the th the information is still present in the source, so this shouldn‘t be a problem.

In order not to require a new stylesheet build the very classes to edit the pseudo-contents are kept in the head section of the respective page. Like this one here:

@media all and (min-width: 20em) {
  table td:nth-child(1):not(:empty):before {
    content: " ";
  }
  table td:nth-child(2):not(:empty):before {
    content: "1st col";
  }
  table td:nth-child(3):not(:empty):before {
    content: "2nd col";
  }
  …
}

/* pseudo classes switched off */
@media all and (min-width: 48em) {
  table td:before {
    display: none;
  }
}

Lists

  1. Ordered List
  2. The misson here is to integrate all structural html without messing too much with it. Which, again, means as little markup as possible, so working in source code is mostly content, not markup.
  3. All we do here is remove non-grid dimensions, paddings and sizes and maintain a figure-backgrund-contrast that fits the environment
  4. Here we use .mono for the entire list.

<section class="row">
  <div class="co-4 card">
    <ul class="smallest">
      <li>item</li>
    </ul>
  </div>
</section>

Definition Lists

this is a definition term
and this would be the definition description, then
grain of salt
We include them here to adjust the few proportional definitions inherent to dl dt dd to the grid system, but nothing beyond that. Do not use this element (nor <ul> elements) to merely create indentation on a page. Although it works, this is a bad practice and obscures the meaning of description lists.
how to use
Just use the unmodified html-tags inside a column (inside a section) to position the list and control the width of the list. To prevent bad readability – should a dl ever make it into a full-width container (on the desktop end) – there is a character-per-line limit in place 75ch and an slightly increased line-height of 1.5, but less than the regular paragraphs here (1.75).
<section class="row-right">
  <div class="co-34">
    <dl>
      <dt>term</dt>
      <dd>description</dd>
    </dl>
  </div>
</section>
Due to the horizontal/vertical ambiguity of definition lists on the one hand and the main-axis/secondary-axis of flex on the other we don‘t aim for two-column layouts with dls, since the definition allows for more than one description for each term, which messes with the alignment a lot. So if we need a grid-like appearance, just use columns.

Disclaimer: Everything here is free to use, but no responsibility is taken for any outcome. Questions & Suggestions: ak at alexkoch dot net (you‘re not a robot, I know). And I don‘t use cookies. Version history