Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS: select all starting from n-th element

How can I select all child elements starting from n-th element? For example I have a div with 7 spans and I need to select all spans starting with 3-rd element, so 4,5,6,7 should be selected.

like image 590
vlad Avatar asked Aug 20 '13 06:08

vlad


3 Answers

div>span:nth-child(2)~span should do the trick. The ~ General Sibling Combinator selects all following elements. The spec is at http://www.w3.org/TR/css3-selectors/#general-sibling-combinators

like image 130
Robin Whittleton Avatar answered Sep 17 '22 23:09

Robin Whittleton


CSS2.1 selector

span + span + span + span {
    /* matching a span that has at least 3 siblings before it */
}

CSS3 selector

span:nth-child(n+4) {
    /* matching from 4th span on */
}
like image 21
Robert Koritnik Avatar answered Sep 19 '22 23:09

Robert Koritnik


You can use

div:nth-child(n+3) {
    // your style here   
}

However, this does not specifically select elements 3-7. Instead, it excludes the first two elements. So it would also select elements 8,9, ...

like image 39
eevaa Avatar answered Sep 21 '22 23:09

eevaa