css时钟效果

本文展示如何结合HTML和CSS构建一个动态的时钟效果。通过纯CSS实现的时钟可以实时显示当前时间,展现了CSS在视觉设计上的潜力。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

css时钟效果

利用html+css做出的时钟效果如下:

index.html


<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        .box {
            width: 200px;
            height: 200px;
            border: 10px solid #ccc;
            border-radius: 110px;
            margin: 100px auto;
            position: relative;
        }
        .line {
            width: 4px;
            height: 200px;
            background: #ccc;
            position: absolute;
            left: 50%;
            margin-left: -2px;
        }
        /*时钟刻度线*/
        .line1 {
            transform: rotate(30deg);
        }
        .line2 {
            transform: rotate(60deg);
        }
        .line3 {
            transform: rotate(90deg);
        }
        .line4 {
            transform: rotate(120deg);
        }
        .line5 {
            transform: rotate(150deg);
        }
        .line6 {
            transform: rotate(180deg);
        }
        /*将刻度线遮住,只留一点点*/
        .mask {
            width: 180px;
            height: 180px;
            background: #fff;
            border-radius: 90px;
            position: absolute;
            margin: 10px;
        }
        /*时针*/
        .hour {
            width: 8px;
            height: 50px;
            background: red;
            position: absolute;
            left: 50%;
            top: 50%;
            margin-left: -4px;
            margin-top: -50px;
            /*43200s匀速转动一圈*/
            animation: move 43200s linear infinite;
            /*设置旋转的中心点为中间底部*/
            transform-origin: center bottom;
        }
        /*分针*/
        .minute {
            width: 6px;
            height: 60px;
            background: blue;
            position: absolute;
            left: 50%;
            top: 50%;
            margin-left: -3px;
            margin-top: -60px;
            /*3600s转一圈,匀速转动*/
            animation: move 3600s linear infinite;
            /*设置旋转的中心点为中间底部*/
            transform-origin: center bottom;
        }
        /*秒针*/
        .second {
            width: 4px;
            height: 80px;
            background: yellow;
            position: absolute;
            left: 50%;
            top: 50%;
            margin-left: -2px;
            margin-top: -80px;
            /*60s转一圈,分60步*/
            animation: move 60s infinite steps(60);
            /*设置旋转的中心点为中间底部*/
            transform-origin: center bottom;
        }
        /*最中心的遮罩层*/
        .circle {
            width: 12px;
            height: 12px;
            border-radius: 6px;
            background: #ccc;
            position: absolute;
            left: 50%;
            margin-left: -6px;
            margin-top: 90px;
        }
        /*旋转从0度到360度*/
        @keyframes move {
            from {
                transform: rotate(0deg);
            }
            to {
                transform: rotate(360deg);
            }
        }
 
    </style>
</head>
<body>
<div class="box">
    <div class="line line1"></div>
    <div class="line line2"></div>
    <div class="line line3"></div>
    <div class="line line4"></div>
    <div class="line line5"></div>
    <div class="line line6"></div>
    <div class="mask"></div>
    <div class="hour"></div>
    <div class="minute"></div>
    <div class="second"></div>
    <div class="circle"></div>
</div>
</body>
</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

ronghua_yang

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

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

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

打赏作者

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

抵扣说明:

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

余额充值