Add a class to the first paragraph

Instead of adding class {.class} per article to the first paragraph, can it be done through the templates?

This worked

If you just want to target the first paragraph on a page, you can do something like:

main p:first-of-type {
  font-weight: bold;
}
1 Like

Why not use CSS and a pseudo-element like nth-of-type?

1 Like

This could get the medal of the most absurdly complicated solution for an extremely simple task :sweat_smile: :sweat_smile: :sweat_smile:

Actually, it was the first paragraph I wanted to target to apply a dropcap in an accessible way. The solution I shared above is also not ideal because it duplicates the first targeted word when copied (e.g. i the first word is The, then the dropcap class is applied but the word now appears twice when copied as TheThe.

Solved the dropcap issue using CSS

main p:not(blockquote p):first-child:first-letter {
<!--- styles go here -->
}

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