简体   繁体   English

如何在 html css 上制作响应式垂直视频?

[英]how to make a responsive vertical video on html css?

I've to insert a vertical video on my website built using html css.我必须在使用 html css 构建的网站上插入垂直视频。 the video must be in left side and it should be responsive.视频必须在左侧,并且应该是响应式的。 This code is displaying the vertical video on left side but on mobile it is not responsive.此代码在左侧显示垂直视频,但在移动设备上没有响应。 what I've to change here to make it responsive.我必须在这里更改以使其响应。

 <div class="vert_video"> <video width="320" height="540" controls> <source src="vertical_video.mp4" type="video/mp4"> Your browser does not support the video tag. </video> </div>

When i change width to 100% it shows the video on entire screen which looks weird on desktop.当我将宽度更改为 100% 时,它会在整个屏幕上显示视频,这在桌面上看起来很奇怪。 help me to make this video responsive.帮助我使此视频具有响应性。

I think you should add vert_video class to video element.我认为您应该将vert_video class 添加到video元素中。

<div>
<video class="vert_video" controls>
  <source src="vertical_video.mp4" type="video/mp4">
  Your browser does not support the video tag.
</video>
</div>

Then, add media queries to your css file.然后,将media查询添加到您的 css 文件中。 In your media queries, you can set max-width or width , which would be useful for you.在您的media查询中,您可以设置max-widthwidth ,这对您很有用。

/*this query will apply for the devices those have width smaller than 480px*/
@media (max-width: 480px) {
  .vert_video {
    width: 100%;
    height: 100%;
  }
}

.vert_video {
    width: 75%;
    height: 75%;
}

you can use this property in css to set your video's width and height based on device width and length您可以在 css 中使用此属性来根据设备宽度和长度设置视频的宽度和高度

@media only screen and (max-width: 520px){

     /* change the width and height of your video here using video property or the video containing class
        it will update the width and height as soon the width of device will go less 
        than 520px,  most of cell phones have width less than 520px(you can change 
        that too)
     */

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM