mhulse / css-issues

Practical CSS code snippets and examples.
11 stars 1 forks source link

Proportional scaling image element #176

Open mhulse opened 6 years ago

mhulse commented 6 years ago
/* <div class="ap_epic"></div> */
.ap_epic {
    background: url(../images/epic.png) no-repeat center top; /* image = 1920 x 1280 */
    background-size: contain;
    display: block;
    padding-bottom: 66.666666666667%; /* (image height = 1280) / (image width = 1920) * 100 */
}

Decent example/explanation found here: https://www.milessebesta.com/web-design/scaling-div-height-proportional-to-width-trick/