建站软件 优化软件 编程软件 网页辅助 站群程序 网站程序 图像处理 资源教程 字体下载 推荐软件


您的位置:首页 > div+css > css3列表实现数字排行

css3列表实现数字排行

时间:2018-10-25 11:12:51  来源:免费模板网 作者:风雪 阅读次数 tagscss3

今天介绍一下不用图片用css实现文章排行榜的效果

css3列表实现数字排行

网页上经常见到这种效果,实现方式很多,比如制作一个图片

css3列表实现数字排行

然后定义 ul属性

css3列表实现数字排行

从后期维护方面这个不太好维护,下面介绍一种纯css实现这一的效果

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

一:使用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>
<li>文章3</li>
    <li>文章4</li>
<li>文章5</li>
    <li>文章6</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>
<li>文章5</li>
    <li>文章6</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 type="text/javascript" src="http://libs.baidu.com/jquery/2.0.0/jquery.js"></script>
<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>

我们可以从以上3种实现方式看出 第2种最简单和便于维护

本文地址:https://www.freemoban.com/bjrm/2018/1025/3062.html

猜你喜欢
栏目推荐
模板推荐

Copyright:www.freemoban.com 免费模板网 All Rights Reserved 网站备案:辽ICP备19014872号-2   辽公网安备 21010602000376号  辽公网安备:42900402000182号

免责声明:本站部分资源来自互联网收集,版权归原创者所有,如果侵犯了你的权益,我们会及时删除侵权内容,联系QQ:1615187561 谢谢合作!