Skip to content

Instantly share code, notes, and snippets.

@gkweb
Created April 7, 2021 23:41
Show Gist options
  • Save gkweb/652c0bcb1b50d44bb18db1f75058dd06 to your computer and use it in GitHub Desktop.
Save gkweb/652c0bcb1b50d44bb18db1f75058dd06 to your computer and use it in GitHub Desktop.
Web vitals easy dimensions
/*
* author: @gkweb
* Add this as an inline style tag to the <head>
*
* Adjust for whatever media query structure you have
* Helps with CLS - The style is there immediately and this means you can set dimensions for every screensize
*/
@media screen and (min-width: 480px) {
[data-sm-width] {
width: attr(data-sm-width);
}
[data-sm-height] {
height: attr(data-sm-height);
}
}
/* Example <img width="100" height="100" data-sm-width="200" data-sm-width="200" /> */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment