Aspect Ratio for Media Elements in CSS


Ensure media elements maintain their aspect ratio as the viewport changes.

Source Code

.responsive-video {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 ratio */
    height: 0;
    overflow: hidden;
}
.responsive-video iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments