CSS Rotate Portrait Image 90 Degrees and Make Image Full Screen

前端 未结 1 1806
清酒与你
清酒与你 2020-12-18 03:33

I have tried many variations. Using an html img, using background image for an element. The idea is that I rotate a portrait oriented image 90 to display on a sideways mou

相关标签:
1条回答
  • 2020-12-18 04:21

    You need to adjust the transform-origin and add some translation to rectify the position. You have to also add overflow:hidden to hide the overflow created by the element because transform is only a visual effect and will not modify the layout of the page and before the tranform you will for sure have an overflow since you inverted the viewport units:

    .rotate {
      transform: rotate(90deg) translateY(-100%);
      transform-origin:top left;
    }
    
    .bg {
      background: url(https://picsum.photos/2000/1000?image=1069) center/cover;
      height: 100vw;
      width: 100vh;
    }
    
    body {
      margin:0;
      overflow:hidden;
    }
    <div class="rotate bg"> </div>

    0 讨论(0)
提交回复
热议问题