On my Wordress blog, I frequently use <hr>
in blog posts. In other posts I use two <hr>
per post – and in others I use no <hr>
.
So right now this is in my CSS:
.entry-content hr {
overflow: visible;
padding: 0;
border: none;
border: 10px solid #74eda7;
border-radius: 8px;
color: green;
text-align: center;
}
.entry-content hr:after {
content: "↓ INSPIRE ↓";
display: inline-block;
position: relative;
top: -0.8em;
font-size: 1.2em;
padding: 0 0.25em;
background: white;
which works fine unless I add another <hr>
to a blog post and then I want a new set of attributes to be applied.
Is there anything I can please add so that a second instance of <hr>
within any one blog post takes on a whole new set of attributes.
Something like this works:
.entry-content hr:nth-child(odd):after {
content: "↓ inspire 2X ↓";
}
.entry-content hr:nth-child(even):after {
content: "↓ INSPIRE ↓";
}
except when I have multiple blog posts per page, the odd and even makes it inconsistent across posts. The first <hr>
should say "Inspire" and the 2nd on any blog post should say "inspire 2x" and a web page can have up to 7 blog posts in total.
I don’t want to manually start adding class names into each blog post.
Any assistance would be greatly appreciated.
3
Answers
Try this way
You can select an element in CSS by an attribute, and in this case you can select by an attribute starting with a particular string.
This snippet selects by article with ids starting with post-
Just replace
nth-child
withnth-of-type
: