简约时钟特效 html+css+js

一. 先看效果(实时显示当前时间):

在这里插入图片描述

二. 实现(最后面有完整代码):

1. 定义盒子,.clock是整个钟,.hour是时针,min是分针,sec是秒针。

 <div class="clock">

       <div class="hour"></div>
       <div class="min"></div>
       <div class="sec"></div>

    </div>

2. 给钟添加基本样式,宽高等等:

 .clock{
   
   
           width: 400px;
           height: 400px;
           background-image: url(clock.png);
           background-size: 100% 100%;
           box-shadow: inset 0  0px 10px 6px rgba(255, 255, 255, 0.5),
                             0  0px 25px   rgba(255, 255, 255, 0.5);
           border-radius: 50%;
           border: 2px solid rgba(255, 255, 255, 0.8);        
           background-color:  rgba(255, 255, 255, 0.2);
           backdrop-filter: blur(15px);
           position: relative;
          
       }

时钟的数字背景图片点我去获取~

box-shadow: inset 0 0px 10px 6px rgba(255, 255, 255, 0.5),
0 0px 25px rgba(255, 255, 255, 0.5); 阴影,可以按照自己喜好设置。
backdrop-filter: blur(15px); 可以让时钟这个元素的后面区域模糊。
position: relative; 相对定位,因为那些分针等要绝对定位;

3. 用伪类给时钟外边再加一层圆圈,主要为了美观,可省略或者修改:

.clock::before{
   
   
           content: '';
           position: absolute;
           top: -30px;
           left: -30px;
           bottom: -30px;
           right: -30px;
           border: 2px solid rgba(255, 255, 255, 0.8);        
           box-shadow: inset 0  0px 25px  rgba(53, 52, 52, 0.5),
                         0  0px 10px  rgba(255, 255, 255, 0.5);
           border-radius: 50%;
           

       }

4. 继续用伪类为时钟添加中间那个小圆点:

.clock::after{
   
   
           content: '';
           position: absolute;
           top: 50%;
           left: 50%;
           width: 20px;
           height: 20px;
           transform: translate(-50%,-50%);
           background-color: rgb(255, 255, 255);
           border-radius: 50%;
           z-index: 3; 
           
           border: 2px solid rgb(79, 146, 96);
           
       }

top: 50%;
left: 50%;
transform: translate(-50%,-50%); 以上这三句可以让圆点居中对齐。
border-radius: 50%; 设置角的弧度。

z-index: 3; 在最外层显示,数值要比时分秒针大;

5. 设置时针样式,绝对定位

.hour{
   
   
           
评论 30
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

北极光之夜。

谢谢~

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

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

打赏作者

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

抵扣说明:

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

余额充值