Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SCSS :not(:last-child) but style is still applied to last element

I have a div that contains different buttons and other divs working as a accordion.
I want to give all the buttons a border-bottom except for the last one.

The UI and html looks like this:

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

And I’ve tried using the :not(:last-child) selector, but as you can see in the first screenshot it isn’t working and the last button still has the border-bottom.

.accordion {
    background-color: #eee !important;
    color: #444;
    cursor: pointer;
    padding: 18px;
    width: 100%;
    text-align: left;
    border: none;
    outline: none;
    transition: 0.4s;

    &:not(:last-child) {
        border-bottom: 1px solid darkgray;
    }
}

What am I doing wrong here?

Thanks in advance

Edit: here is a jsfiddle that demonstrates the problem

https://jsfiddle.net/qpn34myh/

>Solution :

The children are of the parent div. And in your case, the last-child is <div class="panel">. A
better wording would be: The element must be the last element, regardless of selectors.

.accordion:not(:last-child) {
  border-bottom: 1px solid darkgray;
}
<div class="parent">
  <div class="accordion">hi</div>
  <div class="accordion">hi</div>
  <div class="accordion">hi</div>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading