代码之家  ›  专栏  ›  技术社区  ›  Brian Fisher

多个CSS伪类

  •  36
  • Brian Fisher  · 技术社区  · 17 年前

    将多个伪类应用于选择器的正确CSS语法是什么。我想在列表中除最后一项外的每一项后面加上“,”。我正在使用以下css:

    ul.phone_numbers li:after {
        content: ",";
    }
    
    ul.phone_numbers li:last-child:after {
        content: "";
    }
    

    5 回复  |  直到 10 年前
        1
  •  55
  •   Christoph    17 年前

    :last-child :after (或 ::after 在CSS3中)是一个伪元素。

    引用 the standard

    这意味着根据CSS2.1和 CSS3 as well

        2
  •  8
  •   Gumbo    17 年前

    你可以使用 adjacent sibling selector :

    ul.phone_numbers li + li:before {
       content: ",";
    }
    
        3
  •  4
  •   drneel windsurf88    10 年前

    我想回应一下使用伪类选择器进行样式化的可能性 w3 website .

    .ElClass > div:nth-child(2):hover {
        background-color: #fff;
        /*your css styles here ... */
    }
    
        4
  •  3
  •   Linus Caldwell Emperor 2052    13 年前

    您可以通过在标签中添加另一个标签来解决此问题 <li/> 并应用 :after :last-child :之后 针对不同元素:

    ul.phone_numbers li > span:after {
        content: ",";
    }
    
    ul.phone_numbers li:last-child > span:after {
        content: "";
    }