Tailwind CSS: Targeting Child Elements (when you have to)
cekrem.github.io·1d·
Discuss: r/programming
💨Tailwind
Preview
Report Post

The whole point of Tailwind is applying utility classes directly to elements. Styling generic elements like p or div with descendant selectors goes against the grain—it’s the kind of thing Tailwind was designed to replace.

But sometimes you don’t have a choice. Maybe it’s content from a CMS, a third-party component, or dynamically generated HTML. You need to style elements you don’t control. In vanilla CSS, you’d write a selector like .third-party-stuff > p and move on. But what about Tailwind?

The Problem Link to heading

Let’s say you have a container with some paragraphs:

<div class="content">
<p>First paragraph</p>
<p>Second paragraph</p>
</div>

You want all paragraphs inside .content to have specific styling. The traditional approach? Wr…

Similar Posts

Loading similar posts...