Pure CSS3 to create page switching effect example code

Pure CSS3 to create page switching effect example code

The one I wrote before is too complicated, let’s have a simple core

<html>
<head>
    <title></title>
    <style type="text/css">
        * { margin: 0; padding: 0; border: none; } 
        .Bl {
            width: 600px; 
            height: 540px; 
            margin: 0 auto;
            position: relative;
            top: 50%;
            transform: translateY(-50%);
        }
        .Bl > input {
            width: 20%;
            height: 40px;
            position: absolute;
            cursor: pointer;
            opacity: 0;
        }
        .Bl input:nth-of-type(1){ left: 0%; }
        .Bl input:nth-of-type(2){ left: 20%; }
        .Bl input:nth-of-type(3){ left: 40%; }
        .Bl input:nth-of-type(4){ left: 60%; }
        .Bl input:nth-of-type(5){ left: 80%; }
        /*Switch effect*/
        .Bl input:nth-of-type(1):checked ~ span:nth-of-type(1) { color: white; } /* ~ Select sibling elements*/
        .Bl input:nth-of-type(2):checked ~ span:nth-of-type(2) { color: white; }
        .Bl input:nth-of-type(3):checked ~ span:nth-of-type(3) { color: white; }
        .Bl input:nth-of-type(4):checked ~ span:nth-of-type(4) { color: white; }
        .Bl input:nth-of-type(5):checked ~ span:nth-of-type(5) { color: white; }
        .Bl input:nth-of-type(1):checked ~ .pagebox > .pages { }   
        .Bl input:nth-of-type(2):checked ~ .pagebox > .pages { transform: translateY(-100%); }
        .Bl input:nth-of-type(3):checked ~ .pagebox > .pages { transform: translateY(-200%); }
        .Bl input:nth-of-type(4):checked ~ .pagebox > .pages { transform: translateY(-300%); }
        .Bl input:nth-of-type(5):checked ~ .pagebox > .pages { transform: translateY(-400%); }
        span { 
            display: block;
            width: 20%;
            height: 40px; 
            background-color: red;
            float: left;
            text-align: center;
            line-height: 40px;
            font-size: 20px;
        }
        .pagebox,.pages {
            width: 100%; 
            height: 500px;
        }
        .pagebox {
            overflow: hidden;
        }
        .pages {
            transition: all 0.5s;
        }
        .page {
            width: 100%;
            height: 100%;
            text-align: center;
            font-family: "Microsoft YaHei";
            font-size: 30px;
            line-height: 500px;
            color: white;
        }
        .page1 { background-color: pink; }
        .page2 { background-color: blue; }
        .page3 { background-color: red; }
        .page4 { background-color: green; }
        .page5 { background-color: black; }
    </style>
</head>
<body>
    <div class="Bl">
        <input type="radio" name="btn" checked ><span>1</span>
        <input type="radio" name="btn" ><span>2</span>
        <input type="radio" name="btn" ><span>3</span>
        <input type="radio" name="btn" ><span>4</span>
        <input type="radio" name="btn" ><span>5</span>
        <section class="pagebox">
            <div class="pages">
                <div class="page page1">This is page1</div>
                <div class="page page2">This is page2</div>
                <div class="page page3">This is page3</div>
                <div class="page page4">This is page4</div>
                <div class="page page5">This is page5</div>
            </div>
        </section>
    </div>
</body>
</html>

Summarize

The above is the example code for creating page switching effects with pure CSS3 that I introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

<<:  Analysis of MySQL lock wait and deadlock problems

>>:  Web Design Tutorial (3): Design Steps and Thinking

Recommend

How to completely delete and uninstall MySQL in Windows 10

Preface This article introduces a tutorial on how...

Recommended 20 best free English handwriting fonts

Jellyka BeesAntique Handwriting [ank]* Jellyka Cut...

A brief analysis of MySQL's WriteSet parallel replication

【Historical Background】 I have been working as a ...

W3C Tutorial (3): W3C HTML Activities

HTML is a hybrid language used for publishing on ...

Several methods of deploying multiple front-end projects with nginx

I have summarized 3 methods to deploy multiple fr...

SQL implementation of LeetCode (196. Delete duplicate mailboxes)

[LeetCode] 196.Delete Duplicate Emails Write a SQ...

Example of using CSS to achieve semi-transparent background and opaque text

This article introduces an example of how to use ...

More than 100 lines of code to implement react drag hooks

Preface The source code is only more than 100 lin...

js implements the pop-up login box by clicking the pop-up window

This article shares the specific code of js to re...

Detailed explanation of Vue save automatic formatting line break

I searched for many ways to change it online but ...

Solution to Apache cross-domain resource access error

In many cases, large and medium-sized websites wi...

Introduction and examples of hidden fields in HTML

Basic syntax: <input type="hidden" na...

Make your website automatically use IE7 compatibility mode when browsing IE8

Preface To help ensure that your web pages have a ...

Explanation of the configuration and use of MySQL storage engine InnoDB

MyISAM and InnoDB are the most common storage eng...