- This topic has 5 replies, 3 voices, and was last updated 4 years, 12 months ago by
Elvin.
-
AuthorPosts
-
June 3, 2021 at 8:24 am #1808934
MMS
Hi, I’m using the following code successfully to retain the aspect ratio of images on the home page/blog roll view on mobile. However, when you click into the post the ratio shown on the home page previews for the featured image is lost and shows an image that is too tall.
@media(max-width: 1024px) {
.resize-featured-image .post-image img {
height: auto;
-o-object-fit: unset;
object-fit: unset;
}June 3, 2021 at 10:28 am #1809097Ying
StaffCustomer SupportHi Simon,
Try to modify your CSS to this:
@media(max-width: 1024px) { .featured-image img, .resize-featured-image .post-image img { height: auto; -o-object-fit: unset; object-fit: unset; } }June 6, 2021 at 5:42 am #1812119MMS
Hi Thanks, However, the code supplied has reversed the problem. The image aspect ratio of images on the home page/blog roll view on mobile is now too tall i.e. does not maintain aspect ratio, but on individual pages is the correct ratio when viewed on mobile. Is there a way to maintain the aspect ratio of images regardless of screen size across images on the whole site?
June 6, 2021 at 11:11 am #1812554Ying
StaffCustomer SupportThere was a mistake in the CSS, I’ve edited it and removed the media query, so it applies to all devices, could you try again?
.featured-image img, .resize-featured-image .post-image img { height: auto; -o-object-fit: unset; object-fit: unset; }Let me know 🙂
June 6, 2021 at 2:28 pm #1812669MMS
Thanks, Almost there. The images now resize correctly for both the blog home page and individual posts. But the image height that I set to 420px in the settings for Featured Images is being overridden and is showing the full height for images. Is it possible to reduce the height?
June 6, 2021 at 4:31 pm #1812706Elvin
StaffCustomer SupportHi Simon,
Ying’s CSS was meant to keep the aspect ratio while still letting the image occupy 100% of the width.
If you define a specific height but still want to keep it 100% of the width, that will literally break the aspect ratio because you’re basically stretching the image to fit 100% of its container while squishing or stretching it vertically with specified height.
Are you aiming for something like this? – https://share.getcloudapp.com/z8uOwjko
If so, try thiS:
.featured-image img, .resize-featured-image .post-image img { height: 200px; width: auto; } -
AuthorPosts
- You must be logged in to reply to this topic.