Table Maker3schools TranslateImage CompressorFavicon Icon GeneratorCrop & Resize Image
Apu
Apu November 16, 2022 . #css . #Element

How to Select All Child Elements Except the Last One

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 #
save
listen
AI Answer
1 Answer
  1. I have try to add some hover effect on the buttons.  Look at Here
    Reply Delete
    Share
Write Your Answer
loading
back
View All