CSS - Maintain the aspect ratio proportionally across breakpoints

0 votes
49 views
added Apr 9 in CSS by lcjr Lieutenant (12,240 points)
.leaderboard-ad-container {
    width: 100%;
    max-width: 970px; /* Max width of the ad */
    height: auto;
    aspect-ratio: 970 / 250; /* Maintain the 970x250 aspect ratio */
    transition: height 1s ease; /* Smooth transition for resizing */
    background-image: url('https://test/uploads/2019/02/970x250-test.jpg'); /* Default small image */
    background-size: cover;
    background-position: center;
    margin-bottom: 20px; 
    margin-left: auto;
    margin-right: auto;
}

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...