Ozzy
Ozzy

Reputation: 10643

CSS select element which does not follow element

I want to select all P's which do not follow a H3 or a P so:

<img>

<p> this is selected</p>

<p> this is not</p>

<p> this is not</p>

<span>

<p> this is selected</p>

<h3>

<p> this is not</p>

I tried

p + :not(h3, p) and :not(h3, p) + p

but they do not work

what is the solution? Please help

Upvotes: 5

Views: 2051

Answers (3)

John Kurlak
John Kurlak

Reputation: 6680

:not(h3):not(p) + p {
    ...
}

Upvotes: -1

You can express that, as css selector, this way:

*:not(h3):not(p) + p

See working demo

Upvotes: 5

Matt Olan
Matt Olan

Reputation: 1959

Use classes like this...

<img>
<p class="sel"> this is selected</p>
<p> this is not</p>
<p> this is not</p>
<span>
<p class="sel"> this is selected</p>
<h3>
<p> this is not</p>

Then in your CSS you can modify them with...

.sel {
   /* Styling here */
}

Upvotes: -2

Related Questions