Video tag to fill 100% div regardless of ratios

前端 未结 4 1672
無奈伤痛
無奈伤痛 2020-12-14 20:17

I am tying to have a video tag to fill 100% of a div:

a) it doesn\'t need to keep the ratios(otherwise we need to use the overflow:none);

b) fill a div, not

4条回答
  •  Happy的楠姐
    2020-12-14 20:48

    You can use a solution like this one. Ratio dont change, but you can lost the right part of the video.

    video#bgvid {
        position: absolute;
        z-index: 0;
        background: url(mel.jpg) no-repeat;
        background-size: 100% 100%;
        top: 0px;
        left: 0px; /* fixed to left. Replace it by right if you want.*/
        min-width: 100%;
        min-height: 100%;
        width: auto;
        height: auto;
    }
    

    The video will be fix to top left corner. If you want to improve it, I think you will need some JavaScript.

    Edit :

    Just a find a solution with JQuery who can fit your need : simulate background-size:cover on

    Demo

提交回复
热议问题