aboutsummaryrefslogtreecommitdiff
path: root/build/menu-toggle-css/index.html
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/menu-toggle-css/index.html
parentdcfb172704f3afb68a30425029ec834be2883274 (diff)
Remove incorrectly generated files, fix up markdown articles
Diffstat (limited to 'build/menu-toggle-css/index.html')
-rw-r--r--build/menu-toggle-css/index.html28
1 files changed, 2 insertions, 26 deletions
diff --git a/build/menu-toggle-css/index.html b/build/menu-toggle-css/index.html
index 3bb096e..b5b67dc 100644
--- a/build/menu-toggle-css/index.html
+++ b/build/menu-toggle-css/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>Menu Toggle with Pure 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,41 +17,25 @@
<main>
<h1 id="menu-toggle-with-pure-css">Menu Toggle with Pure CSS</h1>
-
<p>2020-10-19</p>
-
<p>When thinking through navigation designs for mobile devices sometimes the best option is to store away the content behind a toggle button. This button would then display the menu items upon interaction. Let me show you how to create such an element with only CSS - no need for JavaScript today!</p>
-
<h2 id="before-we-begin">Before we begin</h2>
-
<p>I would like to point out that the concept of &#8220;toggling&#8221; the main menu (even for mobile) is not always the best solution. If you&#8217;re interested, you can take a look at a previous article I wrote explaining why: <a href="/hamburger-menu-alternative.html">Using Hamburger Menus? Try Sausage Links</a></p>
-
<p>Now that we have mentioned possible pitfalls of relying so heavily on toggle menus, let&#8217;s build one!</p>
-
<h2 id="our-final-product">Our Final Product</h2>
-
<p><img src="/public/images/menu-toggle-css.png" alt="Menu toggle made from pure CSS" /></p>
-
<p><a href="https://codepen.io/bradleytaunt/pen/mdEEvEX">Live CodePen Example</a></p>
-
<h2 id="the-html">The HTML</h2>
-
<p>To implement this design you really don&#8217;t need much in terms of HTML:</p>
-
<ul>
<li><p>A single <code>checkbox</code> input</p></li>
<li><p>A <code>label</code> that corresponds to the <code>checkbox</code></p></li>
<li><p>A <code>nav</code> element to house our unordered list items</p>
-
<p>Menu</p></li>
</ul>
-
<p>That&#8217;s it!</p>
-
<h2 id="the-css">The CSS</h2>
-
<p>The first thing we need to do is &#8220;hide&#8221; the <code>checkbox</code> input element. It&#8217;s important to avoid using <code>display: none</code> or <code>visibility: hidden</code> in order to achieve this. Those CSS properties can negatively impact accessibility (specifically screen readers). So we will be relying on the <code>position</code>, <code>z-index</code> and <code>opacity</code> properties to help us out.</p>
-
<pre><code>&#47;* Set the input position to absolute, send it off screen with zero opacity *&#47;
input[type="checkbox"] {
left: -9999px;
@@ -58,9 +43,7 @@ input[type="checkbox"] {
position: absolute;
}
</code></pre>
-
<p>Then we give our corresponding <code>label</code> a minor face-lift to make it appear more button-like:</p>
-
<pre><code>&#47;* Minor visual styling to make the label more button-y *&#47;
label {
border: 1px solid currentColor;
@@ -69,9 +52,7 @@ label {
padding: 10px;
}
</code></pre>
-
<p>For our main <code>nav</code> element, we want to set it&#8217;s position to <code>absolute</code> in order to avoid any janky page rendering issues that might occur when toggling the menu:</p>
-
<p>`
&#47;* Set nav to absolute (avoids odd page rendering space pop-in) *&#47;
nav {
@@ -79,20 +60,15 @@ label {
position: absolute;
z-index: -2;
}</p>
-
<p>The last step is to actually <em>show</em> the menu if the user toggles the <code>checkbox</code>:</p>
-
<pre><code>&#47;* Show nav when checkbox is checked *&#47;
input[type="checkbox"]:checked ~ nav {
opacity: 1;
z-index: 1;
}
</code></pre>
-
<p>It might not look like much, but you now have a fully functional menu toggle - <strong>made with pure CSS</strong>! </p>
-
<h2 id="with-great-power">With Great Power&#8230;</h2>
-
<p>Although this design is very simple to implement, please remember to use these types of menus wisely. Just because you <em>can</em> do something, doesn&#8217;t always mean you <em>should</em>.</p>
<footer role="contentinfo">
<h2>Menu Navigation</h2>