diff options
Diffstat (limited to 'posts/animated-toggle-tabs.md')
-rw-r--r-- | posts/animated-toggle-tabs.md | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/posts/animated-toggle-tabs.md b/posts/animated-toggle-tabs.md index 5404cfc..e964382 100644 --- a/posts/animated-toggle-tabs.md +++ b/posts/animated-toggle-tabs.md @@ -18,7 +18,7 @@ Let’s get started with the base skeleton. <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> -~~~html +```html <div class="radio-toggles"> <input type="radio" id="option-1" name="radio-options"> <label for="option-1">One-Time</label> @@ -28,14 +28,14 @@ Let’s get started with the base skeleton. <label for="option-3">Free</label> <div class="slide-item"></div> </div> -~~~ +``` ## The CSS 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: -~~~css +```css .radio-toggles { align-items: center; background: #eee; @@ -49,21 +49,21 @@ Now for the main event – the CSS. First we want to style the wrapper that hold padding: 4px; position: relative; } -~~~ +``` Next, we “hide” (only visually) the default `radio` inputs: -~~~css +```css input[type="radio"] { left: -9999px; position: absolute; z-index: -1; } -~~~ +``` Then we give the corresponding `label` elements a little spacing and breathing room: -~~~css +```css label { cursor: pointer; padding: 10px 20px; @@ -71,11 +71,11 @@ label { width: 33.33%; z-index: 2; } -~~~ +``` Remember that `.slide-item` I referenced earlier? That element will be the visual “slider” that animates between the individual radio options. We style that like so: -~~~sh +```sh .slide-item { background: white; border-radius: 9999px; @@ -87,20 +87,20 @@ Remember that `.slide-item` I referenced earlier? That element will be the visua transition: left .4s; z-index: 0; } -~~~ +``` You'll notice the `left`, `height`, and `width` properties utilize the CSS `calc` attributes – this just gives some much needed padding and visual clean-up to the whole tabbed interface. For the finishing touches, we just need to tell the `.slide-item` where to position itself based on which `radio` input is currently selected: -~~~css +```css input[type="radio"]:nth-of-type(1):checked ~ .slide-item { left: 4px; } input[type="radio"]:nth-of-type(3):checked ~ .slide-item { left: calc(66.66% + 4px); } -~~~ +``` That's pretty much it! You now have a fully functional, animated toggle slider with just a set of simple `radio` inputs and pure CSS. |