CSS3 Tab animation example background switching dynamic effect

CSS3 Tab animation example background switching dynamic effect

CSS 3 animation example - dynamic effect of Tab background switching, the specific code is as follows:

<style type="text/css">
.slide-tabs { display:flex; position:relative; border:1px solid #3d3d3d; border-radius:10px; width:150px; overflow:hidden; background:#1c1c1c; }
.slide-tabs * { z-index: 2; }
.slide-tabs input[type=radio] { display:none; }
.slide-tabs .tab { display:flex; align-items:center; justify-content:center; border-radius:9px; height:18px; font-size:12px; color:#fff; cursor:pointer; }
.slide-tabs .glider { display:flex; position:absolute; border-radius:9px; height:18px; background:#3da35a; z-index:1; transition:0.25s ease-out; } /*lower z-index */

.slide-tabs input[type=radio]:checked + label { color:#fff; } /*Modify the current item color as needed*/
.slide-tabs input[type=radio]:nth-of-type(1):checked ~ .glider { transform:translateX(0%); }
.slide-tabs input[type=radio]:nth-of-type(2):checked ~ .glider { transform:translateX(100%); }
.slide-tabs input[type=radio]:nth-of-type(3):checked ~ .glider { transform:translateX(200%); }

.slide-tabs.tabs-3x .tab,
.slide-tabs.tabs-3x .glider { width:50px; }
</style>

<div class="slide-tabs tabs-3x">
    <input type="radio" id="radio-1" value="1" name="tabs" checked="checked">
    <label class="tab" for="radio-1">Daily</label>
    <input type="radio" id="radio-2" value="2" name="tabs">
    <label class="tab" for="radio-2">Week</label>
    <input type="radio" id="radio-3" value="3" name="tabs">
    <label class="tab" for="radio-3">Month</label>
    <span class="glider"></span>
</div>

The code is as above. When you click "Day, Week, Month", in addition to selecting the current item, the green block below will also move. As shown below:

Clever

Using radio, this eliminates the need for JavaScript to set the current item.

At the same time, the radio is hidden, and the for attribute of the label associates the label with the radio. Clicking the label is equivalent to clicking the radio.

Clever 2

The transition is combined with transform:translateX, where translateX refers to the displacement in the x direction.

This concludes this article about the background switching dynamic effects of CSS3 Tab animation examples. For more related CSS3 tab background switching effects content, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

<<:  Introduction to the use and advantages and disadvantages of MySQL triggers

>>:  The meaning of status code in HTTP protocol

Recommend

How to recompile Nginx and add modules

When compiling and installing Nginx, some modules...

MySQL Basic Tutorial Part 1 MySQL5.7.18 Installation and Connection Tutorial

Starting from this article, a new series of artic...

Is your website suitable for IE8?

During the Olympic Games, IE 8 Beta 2 will be rele...

Creative opening effect achieved by combining CSS 3.0 with video

Let me share with you a creative opening realized...

Detailed tutorial on using VMware WorkStation with Docker for Windows

Table of contents 1. Introduction 2. Install Dock...

The basic use of html includes links, style sheets, span and div, etc.

1. Links Hypertext links are very important in HTM...

Pure CSS3 code to implement a running clock

Operation effectCode Implementation html <div ...

One sql statement completes MySQL deduplication and keeps one

A few days ago, when I was working on a requireme...

Detailed explanation of the order of JS object traversal

Some of you may have heard that the order of trav...

Vue implements tab label (label exceeds automatic scrolling)

When the created tab label exceeds the visible ar...

64-bit CentOs7 source code installation mysql-5.6.35 process sharing

First install the dependent packages to avoid pro...

A brief discussion on the principle of React two-way data binding

Table of contents What is two-way data binding Im...

js to achieve interesting countdown effect

js interesting countdown case, for your reference...