Explanation of py-1 [&>p]:inline
- Context: This is a Tailwind CSS utility with an arbitrary selector variant. It’s used in HTML class attributes when Tailwind is configured to allow arbitrary variants (bracketed selectors).
- Breakdown:
- py-1 — applies vertical padding (padding-top and padding-bottom) of Tailwind’s spacing scale value
1(usually 0.25rem). - [&>p]:inline — an arbitrary variant that targets direct child
elements of the element carrying the class and sets theirdisplaytoinline. The&represents the parent selector;>pmeans direct child paragraphs.
- py-1 — applies vertical padding (padding-top and padding-bottom) of Tailwind’s spacing scale value
- Resulting CSS (equivalent):
css
/Parent element /.parent { padding-top: 0.25rem; padding-bottom: 0.25rem;}
/ Direct child paragraphs become inline */.parent > p { display: inline;}
- Use case: When you want an element with small vertical padding, and you need its immediate paragraph children rendered inline (for example, to keep paragraph text flow inline without block breaks) while leaving other descendants unaffected.
- Notes:
-
inline can affect semantics and spacing; consider using spans if inline behavior is intended by markup.
-
Leave a Reply