In this article, we will talk about how to select all child elements except the last one. For example, we have five anchor (a) elements inside the div element as a child.
<div> <a href="#">One</a> <a href="#">Two</a> <a href="#">Three</a> <a href="#">Four</a> <a href="#">Five</a> </div>
Now, we want to style all anchor elements except the last one. So, in this case we can use the css :not() pseudo class with the combination of :last-child pseudo class.
:not(:last-child){
style here
}
See the following example. Here we add the same style to all anchor elements. But we also set a 2px right border on all anchor elements except the last one. Click the Try it Yourself » button to open the code in our online editor.
Example: Style All Child Elements Except the Last One #
Comments (1)
How to Select All Child Elements Except the Last One