html - Maintaining a videos aspect ratio in a responsive layout -
i'm trying maintain videos aspect ratio in responsive layout prevent black edges when layout changes size. far, i've set media queries, while re-sizing there still points video has black edges.
you can see layout , video here http://smedia.lv/ (the showreel video).
the video embedded vimeo iframe , has width , height of 100%. video container width depends on screen size , defined in %, height fixed value.
how can keep aspect ratio of video, doesn't have black edges?
what want fluid width video.
adding few styles container (.video
) , iframe
accomplish this.
.video { height: 410px; width: 964.71px; margin: 0 auto; } iframe { width: 100%; height: 100%; } /* adjust max-width depending on other styles on site. */ @media(max-width: 1046px) { .video { position: relative; /* 40:17 aspect ratio */ padding-bottom: 42.5%; height: 0; width: auto; } iframe { position: absolute; top: 0; left: 0; } }
checkout example below.
note:
- you can use media query setup breakpoint @ point video grow no bigger 964.71x410.
- you need update
padding-bottom
,.video width
, , media query reflect correct aspect ratio of video if changes.
.video { height: 410px; width: 964.71px; margin: 0 auto; } iframe { width: 100%; height: 100%; } @media(max-width: 1046px) { .video { position: relative; /* 40:17 aspect ratio */ padding-bottom: 42.5%; height: 0; width: auto; } iframe { position: absolute; top: 0; left: 0; } }
<div class="video"> <iframe src="https://player.vimeo.com/video/120261170" width="500" height="213" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> </div>
Comments
Post a Comment