CSS :before and :first-child combined

前端 未结 2 844
野性不改
野性不改 2021-02-11 12:16

I\'m using the following code to add separators between my menu items:

#navigation_center li:before {

    content: \"| \";
    color: #fff;

}

2条回答
  •  无人共我
    2021-02-11 12:32

    Try

    #navigation_center li:first-child:before {
        content: '';
    }
    

    Edit: I wanted to expand on this answer with comments made by FelipeAls. The original question used :first which is not a valid CSS selector. Instead, use :first-child. Also the order of the pseudo-selectors is important. The first child selector must come first.

    I tend to think of :before as a kind of modifier to a selector. It does not actually select an element only the space just before the selected element.

提交回复
热议问题