aboutsummaryrefslogtreecommitdiff
path: root/build/tables
diff options
context:
space:
mode:
authorBradley Taunt <bt@btxx.org>2024-06-08 13:43:37 -0400
committerBradley Taunt <bt@btxx.org>2024-06-08 13:43:37 -0400
commit16d28628aca9b2d356de31c319f5e7bc0f5b2b02 (patch)
tree11947abb71e38cbe75116871694a44c33d257763 /build/tables
parentdcfb172704f3afb68a30425029ec834be2883274 (diff)
Remove incorrectly generated files, fix up markdown articles
Diffstat (limited to 'build/tables')
-rw-r--r--build/tables/index.html29
1 files changed, 2 insertions, 27 deletions
diff --git a/build/tables/index.html b/build/tables/index.html
index 224fd6b..bc3c6d2 100644
--- a/build/tables/index.html
+++ b/build/tables/index.html
@@ -3,11 +3,12 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
+ <meta name="color-scheme" content="dark light">
<link rel="icon" href="data:,">
<title>Making Tables Responsive With Minimal CSS</title>
<link href="/atom.xml" type="application/atom+xml" rel="alternate" title="Atom feed for blog posts" />
<link href="/rss.xml" type="application/rss+xml" rel="alternate" title="RSS feed for blog posts" />
-<style>*{box-sizing:border-box;}body{font-family:sans-serif;line-height:1.33;margin:0 auto;max-width:650px;padding:1rem;}img{max-width:100%;}pre{border:1px solid;overflow:auto;padding:5px;}table{text-align:left;width:100%;}.footnotes{font-size:90%;}</style>
+<style>*{box-sizing:border-box;}body{font-family:sans-serif;line-height:1.33;margin:0 auto;max-width:650px;padding:1rem;}blockquote{background:rgba(0,0,0,0.1);border-left:4px solid;padding-left:5px;}img{max-width:100%;}pre{border:1px solid;overflow:auto;padding:5px;}table{text-align:left;width:100%;}.footnotes{font-size:90%;}</style>
</head>
<nav>
@@ -16,36 +17,22 @@
<main>
<h1 id="making-tables-responsive-with-minimal-css">Making Tables Responsive With Minimal CSS</h1>
-
<p>2019-06-11</p>
-
<hr/>
-
<p>I find that the need to create responsive table layouts pops up far more often than most developers would expect. The gut reaction might to be implement some sort of custom grid-system or pull in a pre-built library. Don&#8217;t do this - just use tables and some simple CSS.</p>
-
<p>My recent article, <a href="/html-like-1999">Write HTML Like It&#8217;s 1999</a>, received far more attention than I ever expected on HackerNews. With this attention came a few comments mentioning how <code>table</code> elements don&#8217;t play nice with mobile devices or that it&#8217;s not possible to have a useable layout on smaller screens. <em>This simply isn&#8217;t true</em>.</p>
-
<p>Included below are two separate demos showing how to optimize <code>table</code> HTML for mobile devices using only a minimal amount of CSS. These implementations may not be perfect, but they are far superior to injecting a bunch of custom <code>div</code> elements to <em>look</em> like tables.</p>
-
<h2 id="demo-1-just-let-them-scroll">Demo 1: Just let them scroll</h2>
-
<p>Okay I will admit, this implementation isn&#8217;t the <em>greatest</em> but I find it does work well with huge datasets. Simply set a <code>min-width</code> on your parent <code>table</code> element and the browser will just require the user to scroll the contents horizontally.</p>
-
<pre><code>table {
min-width: 800px; &#47;* Set your desired min-width here *&#47;
}
</code></pre>
-
<p>Check out the CodePen below to see it in action:</p>
-
<p><a href="https://codepen.io/bradleytaunt/pen/ewObbW/">Live CodePen Example</a></p>
-
<p>I actually prefer this method because of its simplicity and function. Users on mobile are familiar with scrolling since it is one of the most basic actions required. Seeing a &#8220;cut-off&#8221; table gives them an instant visual cue that they have the ability to scroll the content.</p>
-
<h2 id="demo-2-more-flexible-than-you-think">Demo 2: More flexible than you think</h2>
-
<p>Using something like <code>flexbox</code> tends to work better when you are working with smaller table datasets. All you need to do is add some minor <code>flexbox</code> layout at your targeted mobile screen size.</p>
-
<pre><code>&#47;* Using 800px as mobile screen in this example *&#47;
@media(max-width: 800px) {
&#47;* Hide the table headings *&#47;
@@ -68,18 +55,13 @@
}
}
</code></pre>
-
<p><a href="https://codepen.io/bradleytaunt/pen/mZbvOb/">Check out the CodePen demo</a></p>
-
<p>There are some caveats with this approach:</p>
-
<ol>
<li>We currently hide the <code>thead</code> row when in mobile view (only visually - screen readers can still scan it)</li>
<li>Some more custom work might be needed depending on how many items per <code>flexbox</code> row makes sense (based on project and dataset)</li>
</ol>
-
<p>You could keep the table headings and style them the same as the <code>tbody</code> contents, but I find hiding them a little cleaner. That choice is entirely up to your personal preference. You can also decide to add heading <code>span</code> elements inside the main <code>tbody</code> elements like so:</p>
-
<pre><code>&#47;* Default span styling - hidden on desktop *&#47;
table td span {
background: #eee;
@@ -121,19 +103,12 @@ table td span {
}
}
</code></pre>
-
<p><a href="https://codepen.io/bradleytaunt/pen/mZdzmZ/">Live CodePen Example</a></p>
-
<p><strong>Updated</strong>: As pointed out by user <a href="https://news.ycombinator.com/user?id=mmoez">mmoez</a>, it is far less repetitive to use <code>:nth-child</code> pseudo selectors to implement the heading fields on mobile (as outlined in this <a href="https://css-tricks.com/responsive-data-tables/">CSS-Tricks article</a>).</p>
-
<h2 id="why-should-i-care-to-use-elements">Why should I care to use <code>table</code> elements?</h2>
-
<p>Simply put: <strong>accessibility</strong> and <strong>proper semantics</strong>.</p>
-
<p>Why use a screwdriver when you need a hammer? Sure, you can make that screwdriver look and <em>almost</em> work the same as a hammer, but for what purpose? Just use the damn hammer1.</p>
-
<p>Have fun making your tables responsive!</p>
-
<p>1 I know, this is a terrible analogy&#8230;</p>
<footer role="contentinfo">
<h2>Menu Navigation</h2>