美文网首页
video标签按比例自由拉伸

video标签按比例自由拉伸

作者: 要快乐的CY | 来源:发表于2019-11-25 22:26 被阅读0次

父集div使用relative定位,padding-bottom值充当空间,子集video元素absolute定位

具体例子如下,比如视频是16:9的比例,这样比例就不会变了,并且适配div的等高比例

css

.vid-wrapper{

    width:100%;

    position:relative;

    padding-bottom:56.25%;    /*9除以16*/

    height: 0;

}

.vid-wrapper video{

    position: absolute;

    top:0;

    left: 0;

    width: 100%;

    height: 100%

}

html

<div class="vid-wrappper">

    <video src=""></video>

</div

相关文章

网友评论

      本文标题:video标签按比例自由拉伸

      本文链接:https://www.haomeiwen.com/subject/lrdswctx.html