FOLASAYO SAMUEL OLAYEMI
SV_D_CURIOUS_SOFTWARE_ENGINEER'S BLOG

SV_D_CURIOUS_SOFTWARE_ENGINEER'S BLOG

How does CSS :not selector work?

FOLASAYO SAMUEL OLAYEMI's photo
FOLASAYO SAMUEL OLAYEMI
·May 9, 2022·

1 min read

Subscribe to my newsletter and never miss my upcoming articles

Play this article

The :not pseudo selector is useful for styling a group of elements, while leaving the last (or specified) element unstyled.

li:not(:last-child) specifies that the styles should apply to all li elements except the :last-child.

Code Sample:

HTML

<ul class="css-not-selector-shortcut">
  <li>One</li>
  <li>Two</li>
  <li>Three</li>
  <li>Four</li>
</ul>

CSS

.css-not-selector-shortcut {
  display: flex;
}

ul {
  padding-left: 0;
}

li {
  list-style-type: none;
  margin: 0;
  padding: 0 0.75rem;
}

li:not(:last-child) {
  border-right: 2px solid #d2d5e4;
}

Output

Screenshot from 2022-05-09 14-49-54.png

Thanks for reading...

Happy Coding!

 
Share this