Combining CSS Pseudo-elements, “:after” the “:last-child”

后端 未结 8 1228
时光说笑
时光说笑 2020-12-22 20:18

I want to make \"grammatically correct\" lists using CSS. This is what I have so far:

The

  • tags are displayed horizontally with commas after t
  • 相关标签:
    8条回答
    • 2020-12-22 21:10

      An old thread, nonetheless someone may benefit from this:

      li:not(:last-child)::after { content: ","; }
      li:last-child::after { content: "."; }
      

      This should work in CSS3 and [untested] CSS2.

      0 讨论(0)
    • 2020-12-22 21:11

      Just To mention, in CSS 3

      :after

      should be used like this

      ::after

      From https://developer.mozilla.org/de/docs/Web/CSS/::after :

      The ::after notation was introduced in CSS 3 in order to establish a discrimination between pseudo-classes and pseudo-elements. Browsers also accept the notation :after introduced in CSS 2.

      So it should be:

      li { display: inline; list-style-type: none; }
      li::after { content: ", "; }
      li:last-child::before { content: "and "; }
      li:last-child::after { content: "."; }
      
      0 讨论(0)
    提交回复
    热议问题