HTML5基础加强css样式篇(css过度效果)(十八)

1.css过度效果简介:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        .box {
            width: 100px;
            height: 100px;
            background-color: #7e64ff;
            /*visibility: hidden;*/

        }

        /*鼠标悬浮在.box时,宽度放大2倍*/
        .box:hover{
            /*设置有过渡效果的CSS属性*/
/*
            对CSS属性的要求:具有“中间值”得CSS样式

            中间值: CSS样式是数值或者可以转化成数值

*/
            /*transition-property: width;*/
            /*transition-property: opacity;*/
            /*transition-property: display;*/
            /*transition-property: visibility;*/
            transition-property: background-color;

            /*#f00 = red*/
            background-color: red;

            /*opacity: 1;*/
            /*display: block;*/


            /*设置过渡持续的时间*/
            transition-duration: 3s;

            /*width: 200px;*/

            /*opacity: 0;*/

            /*display: none;*/

            /*visibility: hidden;*/

        }
        
    </style>
</head>
<body>

<div class="box">

</div>

<script type="text/javascript">


</script>
</body>
</html>
2.css过度效果简单应用:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        .box {
            width: 100px;
            height: 100px;
            background-color: #7e64ff;
            border: 1px solid green;

        }

        /*需求:鼠标悬浮在.box时,宽度放大2倍,背景色变成红色,高度放大2倍*/
        .box:hover{
            /*通过,分割多个样式*/

             /*
            我们不需要特别设置 transition-property:
            浏览器默认为我们增加了 transition-property: all

            */
            /*transition-property: width, background-color, height, border;*/
            /*transition-property: all;*/

            /*仅让宽度产生过渡动画效果*/
            transition-property: width;
            /*当特指某个CSS样式具有过渡动画效果,需要显示设置 transition-property*/

            transition-duration: 3s;

            width: 200px;
            height: 200px;
            background-color: #f00;
            border:  19px solid green;


        }
        
    </style>
</head>
<body>

<div class="box">

</div>

<script type="text/javascript">


</script>
</body>
</html>

3.过度时间设置transition-duration

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>过度时间设置</title>
    <style type="text/css">
        .box {
            width: 100px;
            height: 100px;
            background-color: #7e64ff;
            border: 1px solid green;

        }
        .box:hover{
            /*仅让宽度产生过渡动画效果,过渡时间3ms, 高度4s, 背景色过渡*/
            transition-property: width, height, background-color, border;

            /*transition-duration: 3s;*/
            /*transition-duration: 300ms;*/
            transition-duration: 2s, 4s, 10s;

            /*
            过渡时间值
                ms 毫秒
                s 秒

                */

            width: 200px;
            height: 200px;
            background-color: #f00;
            border: 19px solid green;


        }

    </style>
</head>
<body>

<div class="box">

</div>

<script type="text/javascript">


</script>
</body>
</html>
4.过度延时时间:transition-delay

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        .box, .box1 {
            width: 100px;
            height: 100px;
            background-color: #7e64ff;
            border: 1px solid green;
        }

        body:hover .box{

            /*transition-property: width, height, background-color, border;;*/
            transition-property: width;
            transition-duration: 2s;
            /*过渡延迟执行*/
            /*transition-delay: 1s, .1s;*/

            /*可以设置负值*/
            transition-delay: -1s;

            width: 200px;
            /*height: 200px;*/
            /*background-color: #f00;*/
            /*border: 19px solid green;*/
        }
        body:hover .box1{
            transition-property: width;
            transition-duration: 2s;
            width: 200px;
        }

    </style>
</head>
<body>

<div class="box"></div>
<div class="box1"></div>

<script type="text/javascript">


</script>
</body>
</html>

css过度效果:动态边框应用:

效果图:

代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        .box {
            width: 400px;
            height: 150px;
            background-color: forestgreen;

            position: relative;
        }
        .border-box{
            background-color: orange;
            position: absolute;
        }

        .border-box-top{
            height: 8px;
            width: 0;
        }
        .border-box-right{
            width: 8px;
            height: 0;
            right: 0;
        }
        .border-box-bottom{
            height: 8px;
            width: 0;
            bottom: 0;
            right: 0;
        }
        .border-box-left{
            width: 8px;
            height: 0;
            left: 0;
            bottom: 0;
        }

        /*
            触发时机:鼠标悬浮在 .box
            过渡时间:每个边的过渡时间是1s
            CSS值变化: 0 到指定的大小
        */

        .box:hover .border-box-top{
            width: 100%;
            transition-duration: 1s;
        }

        .box:hover .border-box-right{
            height: 100%;
            transition-duration: 1s;
            transition-delay: 1s;
        }
        .box:hover .border-box-bottom{
            width: 100%;
            transition-duration: 1s;
            transition-delay: 2s;
        }
        .box:hover .border-box-left{
            height: 100%;
            transition-duration: 1s;
            transition-delay: 3s;
        }


    </style>
</head>
<body>

<div class="box">
    <div class="border-box border-box-top"></div>
    <div class="border-box border-box-right"></div>
    <div class="border-box border-box-bottom"></div>
    <div class="border-box border-box-left"></div>
</div>

<script type="text/javascript">


</script>
</body>
</html>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

咸鸭蛋炒饭

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值