0

I have an image which I rotate with css rotate property to 90deg.

Problem, once rotated, the image keep its size and is bigger than the container.

How to fix this with TailwindCSS ?

Here is a playground

Here is the code :

<div class="p-8">
  <div class="h-[315px] w-[560px] border-2 border-solid">
    <img src="https://source.unsplash.com/user/c_v_r/1900x800" class="h-full w-full rotate-90 transform object-fill" />
  </div>
</div>

Johan
  • 2,088
  • 2
  • 9
  • 37

1 Answers1

0

If you wrap the image in a <div> and rotate that, you can then set the image to object-contain so the image fits the height of the container.

<div class="p-8">
  <div class="h-[315px] w-[560px] border-2 border-solid">
    <div class="h-[560px] w-[315px] origin-top-left translate-x-[560px] rotate-90">
      <img src="https://source.unsplash.com/user/c_v_r/1900x800" class="h-full w-full object-contain" />
    </div>
  </div>
</div>

https://play.tailwindcss.com/CXZoglKryG

stickyuser
  • 2,552
  • 15
  • 15