My images stretch when I change viewport (mobile). I want a fixed height (~300px) however when i change viewports the image stretches to accomodate, why doesnt the image just cover the space instead. When i set the height to 100% or auto the image is very small and this isnt what i want.
Please see the below!
Here is my site Read-Only: LINK
(how to share your site Read-Only link )
Example: Image size - 1000_w-
x-542_h
auto
width: auto;
=> set the height to 275
==> The auto width is 507
.
100%
width: 100%
=> set the height to 275
==> The image fill-up the avaiable space no-matter what (= Strech/destroy-aspect ratio).
In general, for responsive images you should use:
width: 100%;
height: auto;
“Crop effect”
If you want height of 275px
no matter what without destroy the aspect-ratio you should use object-fit: cover
. Her example for 16:9 aspect ratio:
** 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…
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.
Hello! - regarding the empty div approach, can this still be linked to a CMS database in the same way in which an image can?
Yes as bg image. (Or use regular img).
Try first, if you won’t succeed i add short example
Hi, I attempted this approach but couldnt get this feature to work. I’d appreciate an example on how to achieve this