How to deselect the first and last child of an element

Hi everyone. I was hoping someone knew how to deselect the first and last child for styling? Basically all I want to do is change the flex direction to column excluding the first and last child of that group… I’ll be searching the web now but if anyone has an answer I would greatly appreciate it. Thanks all

Hey there!

That sounds like something that could be done with jquery. I don’t have much practice with it though, so I could be wrong.

Cheers :+1:

1 Like

Yeahh haha. Realized there are some holes I have to full in first in my understanding and the solution should be easily solvable. Thanks for your reply!! :slight_smile:

You are talking about CSS right?

There are a bunch of different ways of doing it. It kind of depends on the specific usage. Do you have a link you can share?

<div class="parentElement">
  <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
  <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
  <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
  <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
  <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
</div>
.parentElement > p:not(:first-child):not(:last-child) {
  color: red;
}

Edit: Here are some selector reference pages as well.

w3schools: CSS Selector Reference
MDN: Selectors