gtc
(Gerard)
July 9, 2019, 10:27am
1
Hi there,
Is there a way to set a Div element with a responsive aspect ratio? The height should always depend on the width (given by the layout properties).
The only solution is found is placing an image (with the desired AR) inside the div, but doesn’t seem a good solution…
Thanks in advance!
2 Likes
Div:
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
.aspect-ratio-16-9{
padding-top: 56.25%; /* **16:9 Aspect Ratio** */
}
Image inside a div:
** Long scroll but less than 1 min to implement.
“The Problem”
You want to upload difference size images and always keep the aspect ratio of 16:9 (Or any other aspect ratios).
Without any styles this is the result “broken layout”:
[image]
[image]
End result:
[image]
Solution - by “images” CSS trick (cropping-images-object-fit)
Why to use images? (And not bg)
1. Faster loading (Support webflow responsive image ) feature, Better 2. SEO(And better Image SEO), Improve 3. Accessibility (Re…
1 Like