Created
November 17, 2023 07:44
-
-
Save palashmon/35bda7887eb4bc45459d71eca3dda7a5 to your computer and use it in GitHub Desktop.
A More Effective CSS Image Reset
This file contains 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
/** | |
* 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; | |
} |
may be it also necessary to add font-size: 0.75rem e.i. to avoid inhereting from parent
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source: Harry Roberts's post on Twitter
Link: https://twitter.com/csswizardry/status/1717841334462005661