diff options
Diffstat (limited to 'build/flexbox-bar-graphs/index.html')
-rw-r--r-- | build/flexbox-bar-graphs/index.html | 34 |
1 files changed, 2 insertions, 32 deletions
diff --git a/build/flexbox-bar-graphs/index.html b/build/flexbox-bar-graphs/index.html index c705c0d..d458bff 100644 --- a/build/flexbox-bar-graphs/index.html +++ b/build/flexbox-bar-graphs/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>Pure CSS Bar Graphs with Graceful Mobile Fallbacks</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,28 +17,18 @@ <main> <h1 id="pure-css-bar-graphs-with-graceful-mobile-fallbacks">Pure CSS Bar Graphs with Graceful Mobile Fallbacks</h1> - <p>2020-12-08</p> - <p>I recently published a new open source project, Flexbox Bar Graphs, and wanted to share a simple breakdown of how it was built. It isn’t anything mind-blowing, but I like the idea of placing bar graphs in a web page with <em>zero</em> Javascript.</p> - <p>So in the end, this is what our bar graphs will look like on desktop:</p> - <p>And this is how it will look on smaller devices:</p> - <p>Let’s get into the details!</p> - <h2 id="the-html">The HTML</h2> - <p>The main “secret” of this project is that our graphs are constructed out of HTML <em>tables</em>. Now before you freak out - this is perfectly fine and works in our favor quite well.</p> - <ol> <li>If the user has JS disabled –> they will still see our graphs</li> <li>If the user has CSS disabled –> they will see a standard data table set</li> </ol> - <p>All bases are covered!</p> - <pre><code><!-- Using a basic table with our custom data-id --> <table data-id="flexbox-bar-graph"> <caption>Web Performance Results</caption> @@ -72,24 +63,16 @@ </tbody> </table> </code></pre> - <p>Nothing crazy is happening here - just your standard HTML table structure. The one main thing to notice is the <code>--data-set</code> CSS variable placed inline on each data point. This will be important for our CSS to configure the individual bar graphs properly.</p> - <h2 id="the-css">The CSS</h2> - <p>This might look overwhelming if I just dumped the whole CSS file in one big code block, so instead I’m going to break them down into two parts:</p> - <ol> <li>Baseline styling (mobile)</li> <li>Desktop styling</li> </ol> - <h3 id="baseline">Baseline</h3> - <p>Here we target just our table elements with the <code>data-id</code> of <code>flexbox-bar-graph</code>. This allows us to avoid worrying about adding classes or IDs and also avoids conflicts with other non-graph styled tables in our projects.</p> - <p>The base <code>:root</code> element holds all of our bar graph colors. Change these as you see fit!</p> - <pre><code>/* Bar Graph color variables */ :root { --bar-color-1: #357EC7; @@ -125,15 +108,11 @@ margin: 0; } </code></pre> - <h3 id="desktop">Desktop</h3> - <p>Now we set your “visual” bar graphs to show at a set width (in this example it is 1000px and above). That way the “default” styling can target the mobile device screen sizes.</p> - <ul> <li><p>The <code>thead tr th:nth-child(x):before</code> elements create the square “legends” beside each individual data point heading</p></li> <li><p>The <code>tbody tr td:nth-of-type(x) span</code> elements are the bars themselves</p> - <p>@media(min-width: 1000px) { [data-id="flexbox-bar-graph”] { background: transparent; @@ -143,7 +122,6 @@ position: relative; width: 100%; }</p> - <pre><code>[data-id="flexbox-bar-graph"] caption { display: block; font-size: 2rem; @@ -256,16 +234,11 @@ text-align: center; } </code></pre> - <p>}</p></li> </ul> - <h2 id="bonus-styling">Bonus Styling</h2> - <p>In the Flexbox Bar Graph repo, I’ve also included the ability to display these bar graphs horizontally, like so:</p> - <p>The change in CSS is actually quite simple to pull this off - you just need to include the <code>data-layout</code> attribute on the table itself.</p> - <pre><code>[data-layout="horizontal"] tbody { min-height: auto; } @@ -299,11 +272,8 @@ margin-left: 10px; } </code></pre> - <h2 id="thats-all-folks">That’s All Folks!</h2> - <p>That just about sums things up. Feel free to check out the Github repo itself, open any issues you find or fork it for your own!</p> - <ul> <li>Github: <a href="https://github.com/bradleytaunt/flexbox-bar-graphs">https://github.com/bradleytaunt/flexbox-bar-graphs</a></li> <li>Live Demo: <a href="https://flexbox-bar-graphs.netlify.app/">https://flexbox-bar-graphs.netlify.app/</a></li> |