Apply style to everything after first child

Hi there,

Is there a way to apply a style to all elements after the first child?

For example, I want to apply padding to all <p> tags except the first one.

I know I could apply it to the first one and then the others, but wondered if there is a rule which applies after the first?

Thanks

Assuming I have understood correctly, I would apply the style to everything and then apply a different style to first-child.

Would it not be easier to apply it to all, then over-ride it for the first child?

Ninja’d by @Gandalf.

Hi,

you can do this with a general sibling selector:

p:first-of-type ~ p {
  color: red;
}

This will select any <p> on your page that comes somewhere after the first one and make the text red.

2 Likes

I think it can be done using first child in conjunction with a not.

4 Likes

Thanks, this did the job :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.