使用css3实现文章新闻列表排行榜(数字)

列举几个简单的文章排行榜数字效果

一:使用list-style来显示数字、圆点、字母或者图片

<style>
    li{width:300px; border-bottom: 1px dotted #ccc; line-height: 30px; height: 30px; overflow:hidden }
    li{list-style: decimal inside; }
</style>
<ul>
    <li>文章1</li>
    <li>文章2</li>
</ul>

二:使用伪元素:before

使用这种方法,需要在父级标签设置counter-reset:section;

<style>
    ul{counter-reset:section;}
    li{width:300px; border-bottom: 1px dotted #ccc; line-height: 30px; height: 30px; overflow:hidden }
    li:before{counter-increment:section;content:counter(section);display:inline-block;padding:0 6px;margin-right:10px;height:18px;line-height:18px;background:#717070;color:#fff;border-radius:3px;font-size:9px}
    li:nth-child(1):before{background:#ff6a00}
    li:nth-child(2):before{background:#107db4}
    li:nth-child(3):before{background:#56ae11}
</style>
<ul>
    <li>文章1</li>
    <li>文章2</li>
    <li>文章3</li>
    <li>文章4</li>
</ul>

三:使用js实现,先引入jquery

<style>
    ul{counter-reset:section;}
    li{width:300px; border-bottom: 1px dotted #ccc; line-height: 30px; height: 30px; overflow:hidden }
    li i{display:inline-block;font-style:initial;padding:0 6px;margin-right:10px;height:18px;line-height:18px;background:#717070;color:#fff;border-radius:3px;font-size:9px}
    .red1{background:#ff6a00}
    .red2{background:#107db4}
    .red3{background:#56ae11}
</style>
<ul>
    <li>文章1</li>
    <li>文章2</li>
    <li>文章3</li>
    <li>文章4</li>
</ul>
<script>
    listsort()
    //显示排行
    function listsort() {
        var index = 0;
        $("li").each(function () {
            index++;
            var num = $("<i>" + index + "</i>");
            if (index <= 3)
                num.addClass("red" +index);
            $(this).prepend(num);
        });
    }
</script>

比较三种方法,无论是从代码量、还是特效,推荐第二种方法,而且便以维护

地址:http://cssteach.com/html/show-12-88.html

转载于:https://www.cnblogs.com/cssteach/p/5588602.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值