Height attribute on img element not working
See original GitHub issueI was using hyperapp 1.0.1 and this was working
<img src="https://i.pinimg.com/originals/87/b8/67/87b8671c2d08dc83554806539022bde7.gif" height="100px"/>
I update to hyperapp 1.1.2 and now it doesn’t work, but it does without the “px” like this
<img src="https://i.pinimg.com/originals/87/b8/67/87b8671c2d08dc83554806539022bde7.gif" height="100"/>
Here is the Codepen
So I went and check what changes were made, and apparently, this breaks after the version 1.0.2. The problem is here on line 138 where before it was always using setAttribute
if (value == null || value === false) {
element.removeAttribute(name)
} else {
element.setAttribute(name, value)
}
and now is using
if (typeof value === "function" || (name in element && !isSVG)) {
element[name] = value == null ? "" : value
} else if (value != null && value !== false) {
element.setAttribute(name, value)
}
If the element has the attribute and because the image height attribute is an int and not a string it is set to 0.
It’s not a big issue you could just write the number without the “px”. However, there are people who use the “px” like I was doing and then the whole images on the site disappear. Probably there are similar cases like this with other elements.
Issue Analytics
- State:
- Created 6 years ago
- Comments:15 (9 by maintainers)
Top Results From Across the Web
Image height and width not working? - Stack Overflow
The width and height attributes are being overridden by your stylesheet, ... Remove that and your width/height properties on the img tag should...
Read more >Img height attribute not working - The freeCodeCamp Forum
hi, sorry for my English. Normaly when I write in CSS .image { width: 6%; height: 30%; }. it works, but now not…how...
Read more >Img Height In HTML: How Not To Use The Height Attribute »
On a page with a lot of images, this can be a real problem. The simple solution is to include information about an...
Read more >HTML img height Attribute - W3Schools
The height attribute specifies the height of an image, in pixels. Tip: Always specify both the height and width attributes for images. If...
Read more >Setting Height And Width On Images Is Important Again
Fixing The Resizing Problem # · height is set on the element in HTML · width is set on the element in HTML...
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 Free
Top 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
I would prefer to keep current behavior when you must specify image height and with without
px
, not a bug IMO.Agreed