CSS3 selector question for all but first select

前端 未结 3 1248
忘掉有多难
忘掉有多难 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:17

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

    0 讨论(0)
  • 2020-12-23 16:30

    See: http://jsfiddle.net/uDvEt/1/

    .options > div:not(:first-child) select { background:yellow;}
    
    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题