CSS特效(二):利用html和css制作毛玻璃特效和按钮动画效果

最终的效果图片:
在这里插入图片描述在这里插入图片描述
毛玻璃效果:在style标签中,在form表单的before中利用filter的blur属性以及box-shadow的值设置,就可以做出form表单后面的毛玻璃效果背景,还要记得设置form表单的display为flex布局,position为relative,form表单后的毛玻璃特效的position为absolute,所谓”子绝父相“。
按钮动画效果:利用的是button的beforeafter,设置display为block,设置其filter属性blur的值,获得静态的模糊效果,然后改变其hover之前和之后的transform中的translateX属性,转变时间transition设置为1s,即可看到动画效果。
做出这个效果后,我的感悟是:要特别注意position的设置以及overflow:hidden,先规划好整体布局,设置好静态效果,再做动态效果以及更加细节的部分。

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            margin: 0;
            padding: 0;
        }

        .contain {
            width: 100vw;
            height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            background: url(../img/night.jpg) fixed no-repeat;
            background-size: cover;
        }

        .log {
            width: 240px;
            height: 220px;
            display: flex;
            flex-direction: column;
            text-align: center;
            padding: 40px;
            position: relative;
            background: inherit;
            /* overflow很重要  如果没有它的话  毛玻璃特效 特别模糊  虽然不知道为啥 */
            overflow: hidden;
            border-radius: 16px;
            z-index: 100;
        }

        .log::before {
            content: "";
            width: calc(100% + 20px);
            height: calc(100% + 20px);
            display: block;
            position: absolute;
            left: -10px;
            top: -10px;
            background: inherit;
            box-shadow: inset 0 0 200px rgba(255, 255, 255, 0.25);
            filter: blur(6px);
            overflow: hidden;
            border-radius: 14px;
            z-index: -1;
        }

        h2 {
            font-size: 20px;
            font-weight: 400;
            color: rgb(21, 33, 32);
        }

        .log input,
        #btn {
            height: 32px;
            margin: 6px 0;
            background-color: rgba(255, 255, 255, 0.2);
            border-radius: 6px;
            border: none;
        }

        #btn{
            margin-top: 20px;
            cursor:pointer;
            position: relative;
            overflow: hidden;
            transition: 0.7s;
        }

        #btn:hover{
            background-color: rgb(144, 160, 167);
        }

        #btn::before,#btn::after{
            content: "";
            height:90px;
            width: 100px;
            display: block;
            background-color: mediumaquamarine;
            opacity: 0.5;
            filter: blur(30px);
            position: absolute;
            overflow: hidden;
            left:0;
            top:0;
            transform: skewX(-20deg);
            transform: translateX(-100px);
        }

        #btn::after{
            filter:blur(6px);
            width: 40px;
            left:60px;
            opacity: 0;
            background-color: rgba(64, 224, 208, 0.307);
        }

        #btn:hover::before{
            transform: translateX(320px);
            transition: 1s;
            opacity: 1;
           
        }
        #btn:hover::after{
            transform: translateX(320px);
            transition: 1s;
            opacity: 1;
        }
    </style>
</head>

<body>
    <div class="contain">
        <form action="#" class="log">
            <h2>登录</h2>
            <input type="text" name="username" placeholder="username">
            <input type="text" name="password" placeholder="password">
            <button id="btn">登录</button>
        </form>
    </div>
</body>
</html>
  • 5
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
制作播放暂停按钮可以使用HTML5的`<video>`标签和JavaScript来实现。下面是一个示例代码: ```html <!DOCTYPE html> <html> <head> <title>视频播放器</title> <style> /* 播放按钮和暂停按钮的样式 */ .play-button, .pause-button { width: 50px; height: 50px; border-radius: 50%; background-color: #ccc; display: flex; justify-content: center; align-items: center; cursor: pointer; margin: 10px; } /* 暂停按钮的样式 */ .pause-button { display: none; } </style> </head> <body> <video src="video.mp4" controls></video> <div class="play-button"></div> <div class="pause-button"></div> <script> // 获取视频元素 var video = document.querySelector('video'); // 获取播放按钮和暂停按钮 var playButton = document.querySelector('.play-button'); var pauseButton = document.querySelector('.pause-button'); // 点击播放按钮 playButton.onclick = function() { // 隐藏播放按钮,显示暂停按钮 playButton.style.display = 'none'; pauseButton.style.display = 'block'; // 播放视频 video.play(); }; // 点击暂停按钮 pauseButton.onclick = function() { // 隐藏暂停按钮,显示播放按钮 pauseButton.style.display = 'none'; playButton.style.display = 'block'; // 暂停视频 video.pause(); }; </script> </body> </html> ``` 关于CSS播放暂停按钮切换动画特效,可以使用CSS3的`transition`属性来实现。下面是一个示例代码: ```css /* 播放按钮和暂停按钮的样式 */ .play-button, .pause-button { width: 50px; height: 50px; border-radius: 50%; background-color: #ccc; display: flex; justify-content: center; align-items: center; cursor: pointer; margin: 10px; transition: transform .2s ease-in-out; } /* 暂停按钮的样式 */ .pause-button { display: none; } /* 鼠标悬停时的样式 */ .play-button:hover, .pause-button:hover { transform: scale(1.1); } /* 切换动画特效 */ .play-button.hide, .pause-button.show { transform: scale(0); } .pause-button.show, .play-button.hide { transform: scale(1); } ``` 在JavaScript代码中,当点击播放按钮时,使用`element.classList`属性来给播放按钮添加`hide`类,给暂停按钮添加`show`类;当点击暂停按钮时,使用`element.classList`属性来给暂停按钮添加`hide`类,给播放按钮添加`show`类。这样就可以通过CSS3的`transition`属性来实现按钮切换的动画特效了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值