CSS3 selector question for all but first select

前端 未结 3 1247
忘掉有多难
忘掉有多难 2020-12-23 16:02

With the following markup i want a CSS selector to select all but the first select menu within each options div - of which there may be many:



        
3条回答
  •  隐瞒了意图╮
    2020-12-23 16:30

    You need to select the option divs instead of the selects when using :not(:first-child), because every select is the first (and only) child of its parent div:

    div.options > div:not(:first-child) > select
    

    An alternative to :not(:first-child) is to use :nth-child() with a starting offset of 2, like this:

    div.options > div:nth-child(n + 2) > select
    

    Another alternative is with the general sibling combinator ~ (which is supported by IE7+):

    div.options > div ~ div > select
    

提交回复
热议问题