Last active
April 15, 2025 10:22
-
-
Save terryupton/f714651df23e7750fc8b2e497dc24bb2 to your computer and use it in GitHub Desktop.
Image Reset CSS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inspired by Harry Roberts
https://x.com/csswizardry/status/1717841334462005661