When working with CSS3 units, there's a nifty trick to ensure correct dimensions for rotated elements like the <video>
. Instead of using regular percentages, try setting height: 100vw
and width: 100vh
to specify that the height should be based on viewport width and the width on viewport height.
To align the video edges with the viewport after rotation, it's important to adjust the pivot point around which the rotation occurs. A negative margin-top
can help move the video upwards by the specified height (in this case, 100vw
).
By making these adjustments and adding object-fit: cover
to eliminate whitespace, you'll achieve a visually pleasing result:
html,
body {
margin: 0;
}
video {
position: absolute;
transform: rotate(90deg);
transform-origin: bottom left;
width: 100vh;
height: 100vw;
margin-top: -100vw;
object-fit: cover;
z-index: 4;
visibility: visible;
}
<video id="myVideo" src="http://html5demos.com/assets/dizzy.mp4" autoplay loop></video>
I hope these tips are helpful! Feel free to reach out if you have any questions.