Skip to content

Instantly share code, notes, and snippets.

@terryupton
Last active April 15, 2025 10:22
Show Gist options
  • Save terryupton/f714651df23e7750fc8b2e497dc24bb2 to your computer and use it in GitHub Desktop.
Save terryupton/f714651df23e7750fc8b2e497dc24bb2 to your computer and use it in GitHub Desktop.
Image Reset CSS
img {
max-width: 100%;
height: auto;
vertical-align: middle;
font-style: italic;
background-repeat: no-repeat;
background-size: cover;
shape-margin: 0.75rem;
}
/**
* 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.
*/
@terryupton
Copy link
Author

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