Photo by Jonathan Larson on Unsplash
Tables
Natura11y provides an assortment of style options for data tables. Including two different approaches for presenting tables on smaller viewports.
Basic Table
All that is needed for a basic data table is the .table
selector present on the <table>
tag.
<table class="table">
<caption class="screen-reader-only">
Places with columnar jointed volcanics
</caption>
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Country</th>
<th scope="col" class="text-align-right">Map View</th>
</tr>
</thead>
<tbody>
<tr>
<td>Giant’s Causeway</td>
<td>Northern Ireland</td>
<td class="text-align-right">
<a href="#1">Map View</a>
</td>
</tr>
<tr>
<td>Fingal's Cave</td>
<td>Scotland</td>
<td class="text-align-right">
<a href="#1">Map View</a>
</td>
</tr>
<tr>
<td>Garni Gorge</td>
<td>Armenia</td>
<td class="text-align-right">
<a href="#1">Map View</a>
</td>
</tr>
<tr>
<td>Cape Raoul</td>
<td>Tasmania</td>
<td class="text-align-right">
<a href="#1">Map View</a>
</td>
</tr>
<tr>
<td>Svartifoss</td>
<td>Iceland</td>
<td class="text-align-right">
<a href="#1">Map View</a>
</td>
</tr>
</tbody>
</table>
Line # | Details |
---|---|
1 | The parent |
3-5 | The |
Edge to Edge
For an edge to edge look, include the .table--edge
modifier class. This removes the left padding of the first row, and the right padding of the last row.
<table class="table table--edge">
...
</table>
Striped Rows
For striped rows within <tbody>
, include the .table--striped
modifier class.
<table class="table table--striped">
...
</table>
Table Divider
Need horizontal and vertical borders? Include the .table--divider
modifier class.
<table class="table table--divider">
...
</table>
Scrolling Tables
For smaller viewports, nest tables inside the .table-scroll
component. This allows tables to scroll horizontally when the table is wider than the viewport.
Name | Country | Coordinates | Map View |
---|---|---|---|
Giant's Causeway | Northern Ireland | 55°14'27"N 6°30'42"W | Map View |
Fingal's Cave | Scotland | 56°26'02"N 6°20'10"W | Map View |
Garni Gorge | Armenia | 40°11'N 44°31'E | Map View |
Cape Raoul | Tasmania | 43°12'04"S 147°45'48"E | Map View |
Svartifoss | Iceland | 64.023°N 16.975°W | Map View |
Consider the above table. When the viewport is smaller than assigned minimum width (800px), horizontal scrolling is activated. The assigned minimum is set with this CSS variable: --table-scroll-min-width: 800px;
. This value gives you full control of when the scrolling should occur.
Stacking Columns
Another way to display tables for smaller viewports is to stack columns on top of one another. Stacking occurs only until the viewport reaches a specified breakpoint. At this point, the table returns to its original horizontal layout.
For stacking columns, include the .table--stack--{x}
modifier to the .table
selector (Figure 6, line 1). Here, x equals the breakpoint (e.g. lg for the large).
Name | Country | Coordinates | Map View |
---|---|---|---|
Giant's Causeway | Northern Ireland | 55°14'27"N 6°30'42"W | Map View |
Fingal's Cave | Scotland | 56°26'02"N 6°20'10"W | Map View |
Garni Gorge | Armenia | 40°11'N 44°31'E | Map View |
Cape Raoul | Tasmania | 43°12'04"S 147°45'48"E | Map View |
Svartifoss | Iceland | 64.023°N 16.975°W | Map View |
The below example shows the same table appears on a wider (desktop) viewport.
Name | Country | Coordinates | Map View |
---|---|---|---|
Giant's Causeway | Northern Ireland | 55°14'27"N 6°30'42"W | Map View |
Fingal's Cave | Scotland | 56°26'02"N 6°20'10"W | Map View |
Garni Gorge | Armenia | 40°11'N 44°31'E | Map View |
Cape Raoul | Tasmania | 43°12'04"S 147°45'48"E | Map View |
Svartifoss | Iceland | 64.023°N 16.975°W | Map View |
Related CSS Variables
Further customize Tables by redefining any of their related CSS variables as shown below.