Separators between elements without hacks

前端 未结 6 917
猫巷女王i
猫巷女王i 2020-12-14 08:18

One thing I often want to do when laying out a website is to have some elements next to each other, with separators between them. For instance, if I have 3 elements, I\'d wa

6条回答
  •  情深已故
    2020-12-14 09:10

    I often want to have a series of items with semi-colons between them.

    Here's what I do for this:

    .semi-list span:not(:last-of-type)::after {
      content: "; ";
     }
    
    
    Item One Item Two Item Three

    It's a pretty flexible solution.

    Ref:

    • https://www.w3schools.com/cssref/sel_not.asp
    • https://www.w3schools.com/csSref/sel_last-of-type.asp

提交回复
热议问题