Often we encounter a situation in front-end web development where we have a number of elements in HTML and we need to give a specific style to just the last element or to every element except the last element or basically to that element which cannot be selected directly. There comes the use of pseudo selectors.
This article explains the :not(:last-child):after selector. This selector does not select the element after the last child element. It is mostly used to add the content after every child element except the last.
Example 1: This example creates a simple div element. It does not uses :not(:last-child):after selector.
Example 2: After applying the pseudo selector :not(:last-child):after to the above example.
- .div .inner-div: Selects all the elements with class ‘inner-div’ inside elements with ‘div’ class. Here, all three divs have class ‘div’ with two children divs with class ‘inner-div’. It selects all six div element with class name ‘inner-div’.
- The :not() selector excludes the element passed to it from selection.
- The :last-child selector selects the last child.
- Combining these two above selector to excludes the last children (inner-div) of every parent div from the selection.
It selects the three inner-div class elements or every first inner-div element.
- :after This is a great selector to add content (or sometimes, even block-level elements) after the selected elements (Here the first inner-div in every set of inner-divs). So, the content ‘not in the bottom div’ is indeed only added in the top div and not in the bottom div.
- CSS | :root Selector
- CSS | :not Selector
- CSS | :enabled Selector
- CSS | :only-of-type Selector
- CSS | Attribute Selector
- CSS | element Selector
- CSS | :checked Selector
- What does the “+” (plus sign) CSS selector mean?
- How to use a not:first-child selector in CSS?
- CSS | :in-range Selector
- CSS | :disabled Selector
- CSS | :out-of-range Selector
- CSS | :first-child Selector
- CSS | :invalid Selector
- CSS | :empty Selector
- CSS | : valid Selector
- CSS | :read-only Selector
- CSS | :only-child Selector
- CSS | :required Selector
- CSS | ::selection Selector
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai