I'm having the same issue as this, but i'm trying to do it on <video/> element.
I want to make video element sometimes width: 100%, and sometimes height: 100% by aspect ratio of it.
Here's my css
.remoteVideo-container {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 0;
  width: 100vw;
  height: 100vh;
  text-align: center;
  background-color: rgb(45, 48, 53);
}
.remoteVideo {
  object-fit: contain;
  transform: scale(-1, 1);
}
here's my jsx
      <div className="remoteVideo-container">
          <video
            className="remoteVideo"
            autoPlay
            ref={this.remoteVideo}
            muted
          ></video>
      </div>
Result:

You almost got it, you missed the sizing of the video tag. object-position could be also handy :
.remoteVideo {
  height:100%; /* or is max-height:100%; */
  width:100%;  /* or is max-width:100%;  */
  object-fit: contain;
  object-position:center;
  transform: scale(-1, 1);
}
Possible example to run in full page to test behavior on resize, or version based on max-height/max-width 100% https://codepen.io/gc-nomade/pen/bGNzzNj to shrink video if it becomes bigger than the screen .Up to you to choose value for height and width.
body {
  margin: 0;
}
.remoteVideo-container {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 0;
  width: 100vw;
  height: 100vh;
  text-align: center;
  background-color: rgb(45, 48, 53);
}
.remoteVideo {
  height: 100%;
  width: 100%;
  object-fit: contain;
  object-position: center;
  transform: scale(-1, 1);
}<div class="remoteVideo-container">
  <video class="remoteVideo" autoplay muted poster="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/polina.jpg">
    <source  src="http://thenewcode.com/assets/videos/polina.webm" type="video/webm" />
    <source  src="http://thenewcode.com/assets/videos/polina.mp4" type="video/mp4" />
  </video>
</div>If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With