前端初体验——css动画变形练习3:旋转盒子

本练习最终效果如下视频:

旋转盒子

涉及新增知识点有:

  • input 与 lable  input格式单一 无法更改,可以用label来代替input,这样可以通过更改label的样式来表示input标签
<input type="radio" name="aa" id="item1">
<input type="radio" name="aa" id="item2">
<input type="radio" name="aa" id="item3">
<label for="item1">top</label>
<label for="item2">middle</label>
<label for="item3">bottom</label>

同时对input 标签进行

 input{
            display: none;
        }
  •  点击label 触发.tab_body中的动画
#item1:checked~.tab_body{
            transform:rotateX(-90deg);
        }
#item2:checked~ .tab_body{
            transform:rotateX(0deg);
        }
#item3:checked~ .tab_body{
            transform:rotateX(90deg);
        }

本练习代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        body{
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        

        .container{
            width: 700px;
            height: 350px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            perspective: 1300px;


        }

        input{
            display: none;
        }

        .container .tab_body{
            width: 500px;
            height: 300px;
            background: aquamarine;
            position: relative;
            transform-style:preserve-3d ;

            transition: transform 0.5s linear;
            /* transform:rotateY(58deg) rotateX(-45deg); */
        }

        .container .labels{
            width: 150px;
            height: 350px;

        }

        .container .labels label{
            background: rgb(236, 153, 236);
            display: block;
            width:150px;
            height:100px;
            margin-bottom: 25px;
            text-align: center;
            line-height: 100px;
            color: #ffffff;
            
        }
        .container .labels label:hover{
            opacity: 0.7;
        }


        .container .labels label:nth-child(2){
            background: rgb(226, 194, 99);
        }
        .container .labels label:nth-child(3){
            background: rgb(120, 215, 237);
        }

        .container .tab_body .tab_content{
            width: 100%;
            height: 100%;
            background: rgb(236, 153, 236);
            display: flex;

            flex-direction: column;
            justify-content: center;
            align-items: center;
            position: absolute;

            color: #ffffff;
        }
        .container .tab_body .tab_content:nth-child(1){
            transform: translateZ(25px) translateY(-150px) rotateX(90deg) ;
        }

        .container .tab_body .tab_content:nth-child(2){
            background: rgb(226, 194, 99);
            transform: translateZ(175px);
        }
        .container .tab_body .tab_content:nth-child(3){
            background:rgb(120, 215, 237);
            transform: translateZ(25px) translateY(150px) rotateX(-90deg)
        }

        #item1:checked~.tab_body{
            transform:rotateX(-90deg);
        }
        #item2:checked~ .tab_body{
            transform:rotateX(0deg);
        }
        #item3:checked~ .tab_body{
            transform:rotateX(90deg);
        }

    </style>
</head>
<body>

    <div class="container">
        <input type="radio" name="aa" id="item1">
        <input type="radio" name="aa" id="item2">
        <input type="radio" name="aa" id="item3">

        <div class="tab_body">

            <div class="tab_content">
                <h3>top content</h3>
                <p>this is the content</p>
            </div>



            <div class="tab_content">
                <h3>middle content</h3>
                <p>this is the content</p>
            </div>



            <div class="tab_content">
                <h3>bottom content</h3>
                <p>this is the content</p>
            </div> 

        </div>
            

        <div class="labels">
            <label for="item1">top</label>
            <label for="item2">middle</label>
            <label for="item3">bottom</label>

        </div>


    </div>

</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值