img {height:auto} is overriding height attribute in <img />
See original GitHub issuePrologue
A well-known trick for quicker page rendering and better user experience is to explicitly set the height
attribute of an img
(i.e. <img height="30" src="..." />
). This will avoid nasty “jumps” while the page is rendering if the height of an image (being downloaded) is known.
Problem is: afaik, the following rule makes it impossible to take advantage of that technique.
img {
max-width: 100%;
height: auto;
border: 0;
-ms-interpolation-mode: bicubic;
}
Weird as it sounds, It will override the inline attribute value.
I couldn’t find any value for height
(the CSS property, not the img
property) to “undo” this.
I’m not sure the rationale for this particular property in the above rule, so I wonder if someone could shed some light, and a workaround/fix for this issue.
Issue Analytics
- State:
- Created 12 years ago
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Image height and width is overridden by css - Stack Overflow
Tip: Always specify both the height and width attributes for images. If height and width are set, the space required for the image...
Read more >Setting Height And Width On Images Is Important Again
This is actually very easily fixed by adding a height: auto line to the CSS so the height attribute from the HTML is...
Read more >Use CSS to override an image's width and height attributes
Use CSS to override an image's width and height attributes ... media="all"> img.ignore-attributes { width: auto; height: auto; } ...
Read more >Img Height In HTML: How Not To Use The Height Attribute »
The Proper Use of height The purpose of the height (and the width attribute as well) is to inform the browser of the...
Read more >CSS height property - W3Schools
If height: auto; the element will automatically adjust its height to allow ... Note: The min-height and max-height properties override the height property....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You can use the same trick with inline styles as the inline height attribute:
style="height: 100px;"
.I agree, if we wanted
height: auto
we wouldn’t set theheight
attribute. I had a long discussion about it and this seems like the best solution:This solution doesn’t resort to
:not()
, so the support is fairly good.