css中的counter-increment属性

  • 2019-02-23 19:18:00
  • 3,536 次阅读
  • 稿源:天马行空

有些情况下需要将网页中的最新排行或者是点击排行靠前的几篇文章用项目序号标注出来。比如说,给10篇文章加上1-10的项目序号,并且在前三篇文章前标注红色的颜色,方便用户阅读。可能有很多方法去完成,有的人会使用额外标签添span或者i内添加数字用css样式控制,还有人会用伪元素before与额外标签结合使用等情况。

最近时间,偶然看到css中的counter-increment属性可以简单方面的给标签前面添加项目序号,说实话这个属性我还是第一次见到,它就像一个for循环可以自动给li标签或者其他标签加项目序号。具体介绍可以到w3c教程网去瞧瞧。

在这介绍下我的站是如何给文章li标签前加序号。
首先,给li标签定义一个计数器的名字,比如listxh。

li { counter-increment: listxh;}
然后,给每个li标签前加序号。

li:before {content: counter(listxh);}

最后,进行样式的添加调整。counter-increment

TAG:
喜欢 5

文章评论 (12)

  1. 智慧教育说道:

    Hi there mates, pleasant paragraph and pleasant arguments commented at this place, I am genuinely enjoying by these.

    [1楼]网友 Ubuntu Linux | Firefox 60.0.2   
  2. minecraft说道:

    Thanks in support of sharing such a good opinion, post is nice,
    thats why i have read it entirely

    [2楼]网友 Ubuntu Linux | Firefox 59.0   
    • star说道:

      Welcome to visit again.

      [3楼]网友 Windows 7 | 搜狗浏览器 2.X      
  3. minecraft说道:

    Very nice post. I just stumbled upon your weblog and wanted to say
    that I’ve truly enjoyed surfing around your blog posts.
    After all I will be subscribing to your rss feed and I hope you
    write again very soon!

    [4楼]网友 Mac OS X | Chrome 65.0.3325.181   
  4. minecraft说道:

    Hello, I want to subscribe for this webpage
    to get most up-to-date updates, therefore where can i
    do it please assist.

    [5楼]网友 Mac OS X | Safari 601.1.27   
  5. minecraft说道:

    I am in fact pleased to read this web site posts which consists of tons of useful data, thanks for
    providing such data.

    [6楼]网友 Mac OS X | Chrome 68.0.3432.3   
  6. tinyurl.com说道:

    These are truly wonderful ideas in regarding blogging. You have touched some nice factors here.
    Any way keep up wrinting.

    [7楼]网友 Mac OS X | Safari 601.1.27   
    • star说道:

      The harder you work, the luckier you will be.

      [8楼]网友 Windows 7 | 搜狗浏览器 2.X      
  7. minecraft说道:

    Hello There. I found your blog using msn. This is an extremely well written article.
    I’ll be sure to bookmark it and return to read more of your useful info.
    Thanks for the post. I will certainly comeback.

    [9楼]网友 Mac OS X | Chrome 67.0.3396.79   
  8. how to get help in windows 10说道:

    I used to be suggested this blog by means of my cousin. I
    am not positive whether or not this post is written by him as no
    one else understand such certain approximately my difficulty.

    You are incredible! Thank you!

    [10楼]网友 Mac OS X | 未知浏览器   
  9. apex legends android download说道:

    I do not know if it’s just me or if perhaps everybody
    else encountering issues with your website. It appears as though some of the written text in your content are running off the screen. Can somebody else please provide feedback and
    let me know if this is happening to them as well?
    This might be a issue with my browser because I’ve had this happen previously.
    Kudos

    [11楼]网友 Windows NT | Chrome 66.0.3450.0   
  10. gamefly free trial说道:

    Nice post. I learn something totally new and challenging on sites I stumbleupon every day.
    It’s always useful to read through articles from other writers and use something from other sites.

    [12楼]网友 Mac OS X | Chrome 66.0.3359.139   

表情

大眼 可爱 大笑 坏笑 害羞 发怒 折磨 快哭了 大哭 白眼 晕 流汗 困 腼腆 惊讶 憨笑 色 得意 骷髅 囧 睡觉 眨眼 亲亲 疑问 闭嘴 难过 淡定 抗议 鄙视 猪头