Aspect Ratio Boxes Using Padding in CSS


Maintain aspect ratios for content containers using the padding-top trick, especially for responsive video embeds.

Source Code

.aspect-ratio-16-9 {
    position: relative;
    padding-top: 56.25%; /* 16:9 Aspect Ratio */
}
.aspect-ratio-16-9 > iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments