Home › Forums › Pro Support › Width & Height PSI Warning
- This topic has 5 replies, 2 voices, and was last updated 2 years, 7 months ago by
elvin.
-
AuthorPosts
-
February 19, 2021 at 3:34 pm #27060
Ian
ParticipantUsing WP Show Posts with great results. The latest use was listing recent posts in the sidebar. I have set image to be 300×300 but PSI still complains: “Image elements do not have explicit width and height”. Is there a way to pass this warning?
February 21, 2021 at 10:39 pm #27115elvin
ModeratorHi there,
Have you added a custom width and height on the Image tab? If so, that’s known to cause this issue as it removes the width and height attribute of the img element.
Here’s a suggestion:
Leave the image width and height values empty on the Image tab and use CSS to control the width and height.
Example:
.wp-show-posts-image.wpsp-image-center { width: 300px; height:300px; margin: auto; } .wp-show-posts-image img { height: 100%; width: auto !important; object-fit: cover; }
This is done so you could still control the height and width while retaining the
img
height and width attribute from WordPress default image element render.More about this issue:
Dealing with image sizes has always been tricky. We’ve released an Alpha version in an attempt to make it easier for users to control this by adding image size selection option.
See full changelog here: https://wpshowposts.com/wp-show-posts-1-2-0/
February 22, 2021 at 6:18 pm #27176Ian
ParticipantInteresting. Will just using CSS work if some images are portrait and some are landscape of varying sizes? Before I load this, I wonder if this will create unproportional ratios of the original image. Or will object-fit: cover; fix this issue?
February 22, 2021 at 10:39 pm #27195elvin
ModeratorThe CSS was written to keep the container the way you specified (300×300) but I’ve also added
height: 100%;
,width: auto !important;
&object-fit: cover;
to make sure aspect ratio is kept so you don’t get any weird stretching and crop the image to fit 300×300 width and height if incase the image exceeds in width.February 22, 2021 at 11:01 pm #27202Ian
ParticipantHey Elvin,
I tried your code in the customer as a check and the ones with a portrait feature image where it’s taller than wide is not cropped properly. I see white bars on the sides as it’s displaying the tallest portion. I have removed the width and height in WP Show Posts. Mind sharing some CSS that might work to keep all images either at 300×250 or even 300×300?
Wait a minute, how do I send you a private link for the website in question?
February 22, 2021 at 11:54 pm #27210elvin
ModeratorYou can send it here so we can take a look.
https://wpshowposts.com/contact/ -
AuthorPosts
- You must be logged in to reply to this topic.