How to access all the direct children of a div in tailwindcss?

clock icon

asked 3 months ago Asked

message

1 Answers

eye

14 Views

I have this html:

<div class="section">
   <div class="header">header</div>
   <div class="content">
      <div>sub contents 1</div>              
      <div>sub contents 2</div>
   </div>
</div>

I want to access the direct children of div with class "section" which would be divs with class: "header" and "content".

I know with css we can do: div.section > div

But how to do this using tailwindcss?

1 Answers

Space in the selectors need to be replaced by an underscore character in Tailwind classes. For example if you want to select all descendants, not just the direct children then you can use this:

<div class="[&_*]:p-4">...</div>
<div class="[&_p]:mt-0 ">...</div>

Write your answer here

Top Questions