Responsive video iframes (keeping aspect ratio) with only CSS?

后端 未结 4 1488
遥遥无期
遥遥无期 2020-12-08 02:31

I usually use a similar solution to this one. Something like:

.wrapper {
   position: relative;
   width: 100%;
   height: 0;
   padding-bottom: 56.25%;
}
.wr         


        
4条回答
  •  难免孤独
    2020-12-08 02:46

    Use the new CSS viewport units vw and vh (viewport width / viewport height)

    FIDDLE

    iframe {
        width: 100vw; 
        height: 56.25vw; /* 100/56.25 = 560/315 = 1.778 */
        background:red;  
    }
    

    Browser support is also good: IE9+ (caniuse)

提交回复
热议问题