Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add width and height attributes to cover images #519

Merged
merged 5 commits into from
Aug 22, 2021

Conversation

igruenig
Copy link
Contributor

@igruenig igruenig commented Aug 18, 2021

What does this PR change? What problem does it solve?

When using cover images the layout shifts on initial load because the image dimensions can only be determined by the browser after loading the images.

I followed the recommendations from this website linked to from Lighthouse in Chrome and added the width and height attributes to the cover images. From this the browser can determine the aspect ratio before loading any images.

Additionally, in the CSS file I have added the height: auto directive to the .entry-cover img selector. The height is then calculated based on the actual available width.

Was the change discussed in an issue or in the Discussions before?

Fix for #499 in the Discussions

PR Checklist

  • I have enabled maintainer edits for this PR.
  • This change does not include any CDN resources/links.
  • This change does not include any unrelated scripts such as bash and python scripts.

Copy link
Contributor

@danielfdickinson danielfdickinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This are of course my opinions and may not be those of the maintainer.

layouts/partials/cover.html Outdated Show resolved Hide resolved
layouts/partials/cover.html Outdated Show resolved Hide resolved
layouts/partials/cover.html Outdated Show resolved Hide resolved
Copy link
Contributor

@danielfdickinson danielfdickinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the changes. I'm not sure what I think of the formatting changes, mostly because I'm not sure what the maintainer prefers, but this looks good. Also, there is an issue #499 you might want to reference.

@igruenig
Copy link
Contributor Author

Thank you for the hint! I inserted the link in my initial comment.

@sonarcloud
Copy link

sonarcloud bot commented Aug 20, 2021

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@adityatelange adityatelange merged commit dcbe627 into adityatelange:master Aug 22, 2021
@igruenig igruenig deleted the pr-avoid-layout-shifts branch October 27, 2021 15:12
kylethedeveloper pushed a commit to kylethedeveloper/hugo-PaperMod that referenced this pull request Feb 21, 2023
- Ensures that the browser can allocate the correct amount of space in the document while the image is loading.
- Reduces CLS adityatelange#499
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants