Joined May 2013
·
Posted to
CSS selector trick: select all elements except the first
over 1 year
ago
This is clever but ugly. It isn't intuitive what elements the selector will affect.
This is clever but ugly. It isn't intuitive what elements the selector will affect.
@thomshouse: It's unintuitive in that when you look at the selector it's not immediately apparent to another developer (or you in 6 months time) what it will affect. It's arguable that there isn't really a use of a selector that does this which is both inuitive and cross-browser compatible, but overriding the style with first:child would work ok as long as you're ok with the caveats when using that pseudo-selector with IE7 and 8.
Personally I'd try for a server-side addition of a 'first' class, and then override the style if I really needed to select all but the first element, but That's not a CSS-only solution. The method detailed here has merit! It is clever and it works, but I just don't think it's very elegant and could end up costing development time, especially if you're working as part of a team. Just a consideration.