[CSS] Select N element and following
Sometimes we want to select all elements except first one. We can easily do that with + selector.
.nav li + li {
border-left: 1px solid #ccc;
}
This way we can add separators between links in navigation without separator for first link. Another example is a list like this:
To add separators, we have to start from 3rd link:
.nav li + li + li {
border-top: 1px solid #ccc;
}
It's easy technique and have more power than :first-child selector.
Preview of 1st example and 2nd
Written by Kasper Mikiewicz
Related protips
1 Response
Nice technique but its use is limited to the fact you must know the number of elements you have whereas usually you can't predict this aspect. So at the end the :first-child technique would be more appropriate.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Css
Authors
Related Tags
#css
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#