Skip to content

Instantly share code, notes, and snippets.

@palashmon
Created November 17, 2023 07:44
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save palashmon/35bda7887eb4bc45459d71eca3dda7a5 to your computer and use it in GitHub Desktop.
Save palashmon/35bda7887eb4bc45459d71eca3dda7a5 to your computer and use it in GitHub Desktop.
A More Effective CSS Image Reset
/**
* This CSS block is a More Effective CSS Image Reset.
* It resets the default styles of an image element
* and adds some additional styles to improve its rendering.
*
* The `max-width: 100%;` ensures that the image does not exceed its container's width,
* while maintaining its aspect ratio with `height: auto;`.
*
* The `vertical-align: middle;` aligns the image vertically with the text.
*
* The `font-style: italic;` adds a slight italic effect to the image alt text.
*
* The `background-repeat: no-repeat;` ensures that the image does not repeat itself.
*
* The `background-size: cover;` ensures that the image fills its container without repeating.
*
* Finally, the `shape-margin: 1rem;` adds some margin around the image to improve its spacing with other elements.
*/
img {
max-width: 100%;
height: auto;
vertical-align: middle;
font-style: italic;
background-repeat: no-repeat;
background-size: cover;
shape-margin: 1rem;
}
@palashmon
Copy link
Author

Source: Harry Roberts's post on Twitter
Link: https://twitter.com/csswizardry/status/1717841334462005661

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment