Last Updated: October 11, 2021
·
1.499K
· idered

[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;
}

Picture

This way we can add separators between links in navigation without separator for first link. Another example is a list like this:

Picture

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

1 Response
Add your 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 ·