Apply CSS class generated HTML element #3161
-
Hi, I would like to know how to apply a CSS class on a generated HTML element. I explain to you: I use markdown_to_html filter Twig. <div class="sm:divide-y sm:divide-gray-200 space-y-2 sm:space-y-4">
<div>{{ post.content|markdown_to_html|raw }}</div>
</div> The generated content is as follows: <div class="sm:divide-y sm:divide-gray-200 space-y-2 sm:space-y-4">
<div>
<p>Dolores autem molestiae sit doloribus ex ut eveniet occaecati unde.</p>
<ul>
<li>Nobis et rerum quam unde.</li>
<li>Dicta veniam architecto quod rerum nobis.</li>
<li>Inventore quaerat quis aut excepturi dolor ea.</li>
</ul>
</div>
</div> I would like to add 2 CSS classes to the HTML element Do I have to create a component like the following? <div class="sm:divide-y sm:divide-gray-200 space-y-2 sm:space-y-4">
<div class="post-content">{{ post.content|markdown_to_html|raw }}</div>
</div> @tailwind base;
@tailwind components;
@tailwind utilities;
@layer components {
.post-content ul {
@apply list-inside list-disc;
}
} What is the good practice? Thanks ;) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Yep that's the recommended approach! It's how our official typography plugin works for example. |
Beta Was this translation helpful? Give feedback.
-
Thank you for your answer @adamwathan ! |
Beta Was this translation helpful? Give feedback.
Yep that's the recommended approach! It's how our official typography plugin works for example.