Style last element in rich text block

When I add a rich text block, I can style certain elements such as headline, paragraphs, etc. I have added now multiple paragraphs where the bottom margin is 20px:

<h1></h1>
<p></p>
<p></p>
<p></p>
p {margin-bottom:20px;}

I would like to apply to the last paragraph a bottom margin of 0px. How can I do this?

I used a quick fix as solution which is to set the bottom margin of the rich text container to -20px but this is not a good solution. When the last element is a list or headline without bottom margin, then this fix won’t work.

Sorry, I don’t have a real example on my website but post anyhow the link to my read-only site.


Here is my site Read-Only: https://swiss-broker.webflow.io

Custom CSS is likely your easiest bet here.

It looks like the :last-child pseudoselector is what you want.

<style>
#myRichTextElement p:last-child {
  margin-bottom:20px;
}
</style>

There is also a :last-of-type pseudoselector however it will select the last of your <p>'s even if that element is not at the very end of your rich text content.