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

后端 未结 8 1226
时光说笑
时光说笑 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 20:59

      I do like this for list items in

      elements. Consider the following markup:

      
        
    • Profile
    • Options
    • Logout
    • I style it with the following CSS:

      menu > li {
        display: inline;
      }
      
      menu > li::after {
        content: ' | ';
      }
      
      menu > li:last-child::after {
        content: '';
      }
      

      This will display:

      Profile | Options | Logout
      

      And this is possible because of what Martin Atkins explained on his comment

      Note that in CSS 2 you would use :after, not ::after. If you use CSS 3, use ::after (two semi-columns) because ::after is a pseudo-element (a single semi-column is for pseudo-classes).

    提交回复
    热议问题