Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Tailwind/CSS: Why my div is not fitting the width of the image but expanding to longer width?

My div (highlighted with background yellow) is expanding horizontally i.e., it’s width is increasing. I think it is increasing to the full width of the image i.e., 800px + padding. How can I make sure this div’s width and height is equal to the shrunk containing image? So that the next element with text- "Test" is displayed right next to it. Thanks!

<script src="https://cdn.tailwindcss.com/3.4.3"></script>

<div class="flex max-h-96">
  <div class="flex w-fit bg-yellow-100 p-2">
    <img src="https://placehold.co/800x1000" alt="MAIN_IMAGE" />
  </div>
  <div>Test</div>
</div>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I think the m-h tailwind property is causing the problem. Set its height not its max-height. Also make sure the both the image and the image’s parent take the the full height of each their parents.

<script src="https://cdn.tailwindcss.com/3.4.3"></script>

<div class="flex h-96"> <!-- don't use max height -->
  <div class="bg-yellow-100 h-full p-2"> <!-- let this element take the full height of its parent -->
    <img class="h-full" src="https://placehold.co/800x1000" alt="MAIN_IMAGE" /> <!-- and this one too -->
  </div>
  <div>Test</div>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading