css计数器之小案例

css计数器
counter-reset:counterName //创建或重置计数器
counter-increment:counterName //递增变量
content:插入生成的内容 //一般和伪类 ::before::after搭配使用
counter(counterName)或counters(函数) //将计数器的值添加到元素

先展示效果图,然后下面是代码。虽然看着简单,但用到的知识点蛮多的。
最重要的是代码的可扩展性
效果图展示

<!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 {
            counter-reset: counter;
        }

        .circle_container {
            width: 100%;
            height: 80px;
            display: flex;
            justify-content: center;
            align-items: center;
            /* margin-top: 30px; */
        }

        .circle_container li {
            counter-increment: counter;
            list-style: none;
            flex-grow: 1;
            position: relative;
        }
        .circle_container li:last-child{
            flex-grow: 0;
        }
        .circle {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background-color: #BCBCBC;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        li .line{
            width: 100%;
            height: 2px;
            background-color: #bcbcbc;
            position: absolute;
            top: 20px;
            left: 0;
            z-index: -1;
        }
        .circle_container li:last-child .line{
            display: none;
        }
        .circle_num {
            width: 32px;
            height: 32px;
            border-radius: 50%;
            line-height: 35px;
            text-align: center;
            color: #fff;
            font-weight: bold;
        }
        .circle_num::after {
            content: counter(counter)
        }
        .circle_detail {
            margin-top: 10px;
            color: #444;
            font-weight: bold;

        }
        .circle_detail::after {
            content: '第'counter(counter)'步'
        }
        .finished .circle{
            background-color:#00BC9B;
        }
        .finished .circle_num{
            border: 2px solid #fff;
        }
        .finished .circle_detail{
            color:#00BC9B;
        }
        .finished .line{
            background-color: #00BC9B;
        }
    </style>
</head>

<body>
    <ul class="circle_container">
        <li class="finished">
            <div class="line"></div>
            <div class='circle'>
                <span class='circle_num'></span>
            </div>
            <div class="circle_detail"></div>
        </li>
        <li class="finished">
            <div class="line"></div>
            <div class='circle'>
                <div class='circle_num'></div>
            </div>
            <div class="circle_detail"></div>
        </li>
        <li>
            <div class="line"></div>
            <div class='circle'>
                <span class='circle_num'></span>
            </div>
            <div class="circle_detail"></div>
        </li>
        <li>
            <div class="line"></div>
            <div class='circle'>
                <span class='circle_num'></span>
            </div>
            <div class="circle_detail"></div>
        </li>
    </ul>
</body>

</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

哆啦咪唏

看到这里了,不留下点什么吗

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

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

打赏作者

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

抵扣说明:

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

余额充值