CSS :before and :first-child combined

前端 未结 2 544
盖世英雄少女心
盖世英雄少女心 2021-02-11 12:09

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:20

    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.

提交回复
热议问题