aboutsummaryrefslogtreecommitdiff
path: root/build/animated-toggle-tabs/index.html
diff options
context:
space:
mode:
authorbt <bt@btxx.org>2024-06-08 13:22:19 -0400
committerbt <bt@btxx.org>2024-06-08 13:22:19 -0400
commitdcfb172704f3afb68a30425029ec834be2883274 (patch)
tree02ac480745db802d7af03f3213a0c568322170e3 /build/animated-toggle-tabs/index.html
parente146f8a64c793c337999ce316b16ebe5fe6f2dab (diff)
More content porting, on-going markdown changes for lowdown support
Diffstat (limited to 'build/animated-toggle-tabs/index.html')
-rw-r--r--build/animated-toggle-tabs/index.html67
1 files changed, 44 insertions, 23 deletions
diff --git a/build/animated-toggle-tabs/index.html b/build/animated-toggle-tabs/index.html
index a624b60..599d6c2 100644
--- a/build/animated-toggle-tabs/index.html
+++ b/build/animated-toggle-tabs/index.html
@@ -1,44 +1,55 @@
<!doctype html>
-<html lang="en" id="top">
+<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="data:,">
<title>Animated Radio Tab Toggles</title>
- <link href="https://bt.ht/atom.xml" type="application/atom+xml" rel="alternate" title="Atom feed for blog posts" />
- <style>*{box-sizing:border-box;}body{font-family:sans-serif;margin:0 auto;max-width:650px;padding:1rem;}img{max-width:100%;}pre{overflow:auto;}table{text-align:left;width:100%;}</style>
+ <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>
</head>
<nav>
- <a href="#menu">Menu &darr;</a>
+ <a href="#menu">Menu &darr;</a>
</nav>
<main>
-<h1>Animated Radio Tab Toggles</h1>
+<h1 id="animated-radio-tab-toggles">Animated Radio Tab Toggles</h1>
+
<p>2021-01-05</p>
+
<p><em>In this demo tutorial, we are making the assumption</em> that we need to create a radio slide toggle for our made-up payment options. For this we want to display 3 simple payment choices to the user:</p>
+
<ul>
<li>One-time payment</li>
<li>Recurring payment</li>
<li>Free tier payment</li>
</ul>
-<h2>The Final Demo</h2>
+
+<h2 id="the-final-demo">The Final Demo</h2>
+
<p><a href="https://codepen.io/bradleytaunt/embed/vYXjpLO">Live CodePen</a></p>
+
<p>Let’s get started with the base skeleton.</p>
-<h2>The HTML</h2>
-<p><p>There isn't anything special happening here. We just contain all our <code>labels</code> and <code>inputs</code> into a <code>.radio-toggles</code> wrapper, make sure those <code>labels</code> are each properly connected to their corresponding <code>inputs</code>, and then add an empty <code>.slide-item</code> element (more on that later).</p></p>
-<pre><code>&lt;div class=&quot;radio-toggles&quot;&gt;
- &lt;input type=&quot;radio&quot; id=&quot;option-1&quot; name=&quot;radio-options&quot;&gt;
- &lt;label for=&quot;option-1&quot;&gt;One-Time&lt;/label&gt;
- &lt;input type=&quot;radio&quot; id=&quot;option-2&quot; name=&quot;radio-options&quot; checked&gt;
- &lt;label for=&quot;option-2&quot;&gt;Recurring&lt;/label&gt;
- &lt;input type=&quot;radio&quot; id=&quot;option-3&quot; name=&quot;radio-options&quot;&gt;
- &lt;label for=&quot;option-3&quot;&gt;Free&lt;/label&gt;
- &lt;div class=&quot;slide-item&quot;&gt;&lt;/div&gt;
-&lt;/div&gt;
+
+<h2 id="the-html">The HTML</h2>
+
+<pre><code>&#60;div class="radio-toggles"&#62;
+ &#60;input type="radio" id="option-1" name="radio-options"&#62;
+ &#60;label for="option-1"&#62;One-Time&#60;&#47;label&#62;
+ &#60;input type="radio" id="option-2" name="radio-options" checked&#62;
+ &#60;label for="option-2"&#62;Recurring&#60;&#47;label&#62;
+ &#60;input type="radio" id="option-3" name="radio-options"&#62;
+ &#60;label for="option-3"&#62;Free&#60;&#47;label&#62;
+ &#60;div class="slide-item"&#62;&#60;&#47;div&#62;
+&#60;&#47;div&#62;
</code></pre>
-<h2>The CSS</h2>
+
+<h2 id="the-css">The CSS</h2>
+
<p>Now for the main event – the CSS. First we want to style the wrapper that holds all of our pieces together. You can tweak this to your liking, but I prefer a simple and clean style:</p>
+
<pre><code>.radio-toggles {
align-items: center;
background: #eee;
@@ -53,14 +64,18 @@
position: relative;
}
</code></pre>
+
<p>Next, we “hide” (only visually) the default <code>radio</code> inputs:</p>
-<pre><code>input[type=&quot;radio&quot;] {
+
+<pre><code>input[type="radio"] {
left: -9999px;
position: absolute;
z-index: -1;
}
</code></pre>
+
<p>Then we give the corresponding <code>label</code> elements a little spacing and breathing room:</p>
+
<pre><code>label {
cursor: pointer;
padding: 10px 20px;
@@ -69,7 +84,9 @@
z-index: 2;
}
</code></pre>
+
<p>Remember that <code>.slide-item</code> I referenced earlier? That element will be the visual “slider” that animates between the individual radio options. We style that like so:</p>
+
<pre><code>.slide-item {
background: white;
border-radius: 9999px;
@@ -82,16 +99,20 @@
z-index: 0;
}
</code></pre>
-<p>You'll notice the <code>left</code>, <code>height</code>, and <code>width</code> properties utilize the CSS <code>calc</code> attributes – this just gives some much needed padding and visual clean-up to the whole tabbed interface.</p>
+
+<p>You&#8217;ll notice the <code>left</code>, <code>height</code>, and <code>width</code> properties utilize the CSS <code>calc</code> attributes – this just gives some much needed padding and visual clean-up to the whole tabbed interface.</p>
+
<p>For the finishing touches, we just need to tell the <code>.slide-item</code> where to position itself based on which <code>radio</code> input is currently selected:</p>
-<pre><code>input[type=&quot;radio&quot;]:nth-of-type(1):checked ~ .slide-item {
+
+<pre><code>input[type="radio"]:nth-of-type(1):checked ~ .slide-item {
left: 4px;
}
-input[type=&quot;radio&quot;]:nth-of-type(3):checked ~ .slide-item {
+input[type="radio"]:nth-of-type(3):checked ~ .slide-item {
left: calc(66.66% + 4px);
}
</code></pre>
-<p>That's pretty much it! You now have a fully functional, animated toggle slider with just a set of simple <code>radio</code> inputs and pure CSS.</p>
+
+<p>That&#8217;s pretty much it! You now have a fully functional, animated toggle slider with just a set of simple <code>radio</code> inputs and pure CSS.</p>
<footer role="contentinfo">
<h2>Menu Navigation</h2>
<ul id="menu">