Style paragraphs preceded by heading level element

I wonder if it is possible to style a paragraph that is not preceded by a heading?

I think the rule would look something like this:

  p (direction for "without/not preceded by") h1, h2, h3, h4, h5, h6 {

Or ... this rule should be written for the opposite:

  h1, h2, h3, h4, h5, h6 + p {

... therefore paragraphs by default may have the style needed for a paragraph not preceding the heading.

Regards, Dale

+3
source share
3 answers

I am sure that you should write the opposite, as you described. However, two important points:

  • The first solution that comes to my mind is to use :notor pseudo-denial . However, this requires a simple selector, so

    :not(h1, h2, h3, h4, h5, h6) + p
    

    will be illegal.

  • , + p h6; SelectORacle.

    h1 + p, h2 + p, h3 + p, h4 + p, h5 + p, h6 + p
    
+5

. , , , :

p {//styles here}

, , , :

h1 + p, h2 + p, etc {//styles here}

, . , , .

EDIT: , , ... , background-color: red p, p, h, background-color none ..

+1

Thanks for the suggestions guys.

I felt that there was some kind of selector that would do the job, but it looks very tricky to use this one.

I will go with:

 p {

and then, below in cascade:

 h1 + p, h2 + p, h3 + p, h4 + p, h5 + p, h6 + p {

It is annoying that

 p {

is an exception, not a rule: D

+1
source

All Articles