DEV Community

Cover image for The strange <img> gap in HTML

The strange <img> gap in HTML

Christian Kaindl on September 23, 2017

There are many frustrations that I have had in my short dev game so far, and one of them crossed my eyes very recently again while I was working on...
Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
davejs profile image
David Leger

Very insightful. Everyone knows the best way to help beginners is to make them feel stupid and unwelcome for sharing what they’ve learned...

Collapse
 
Sloan, the sloth mascot
Comment deleted
 
davejs profile image
David Leger

It is not wrong to correct mistakes, but all you have done here is berate a beginner for sharing something that they have learned, calling it clickbait, and then question them for not having learned it earlier. This article clearly wasn’t written for you.
You haven’t corrected a mistake.

What exactly is wrong with the title anyway? What would you call this article?
This is a side tangent: If you ever onboard junior devs please take more care when communicating with them.

Collapse
 
christiankaindl profile image
Christian Kaindl

Thank you for commenting.

To me it wasn't obvious from the beginning and it was also not one of the first things I learned when starting with HTML (by making W3School tutorials). It was not intuitive for me to suggest that IMG elements are inline elements just by looking at websites.

Also, I guess that - despite this being in the HTML spec since version 1 - a lot of developers have experienced similar issues when using images, without knowing what causes them. It is a simple thing, but it wasn't obvious to me and I think it is not obvious to quite a few developers out there.
I think it doesn't matter if it is simple or not or if it is already around for years. If people struggle with it or don't know what it is about, it's something worth writing about. I tried to fill a gap, because I couldn't find a comprehensive article myself and wanted to make a valuable contribution. Dev.to is the perfect community for such - a community that is grateful for learning from others people's learnings, and sharing their own learnings, which is what I did.

So in that sense it was the strange <img> gap that was somehow there for me. And, assuming that other people have the same problem, the title The strange <img> gap in HTML is no clickbait at all, but rather the most helpful title for the ones who have the problem themselves, and who do not simply know that it is so simple because it was in the HTML spec since version 1. Writing an article about it was the choice that reached the most people - and hopefully helped a lot of them.

I hope that clarifies my intentions for the article.

Collapse
 
Sloan, the sloth mascot
Comment deleted
 
christiankaindl profile image
Christian Kaindl

I added an additional paragraph and further reading links to the end of the article.

If you have suggestions for articles and links, please let me know.

Collapse
 
igorjoergensen profile image
IgorJoergensen

I often find myself looking at the element panel in my console and then looking at what rules an element inherits from the agent.

I can only recommend using that whenever you have a little downtime - a lot to learn by just inspecting.

Thank you for sharing your findings, the breakdown you made are actually quite good.

Collapse
 
lexlohr profile image
Alex Lohr

In most cases, display: inline-block is what you want (unless you want float, which inherently formats as block content.

Collapse
 
christiankaindl profile image
Christian Kaindl

For me inline-block does not fix this particular issue. But inline-block or inline-flex can be used and they also give more flexibility.

Collapse
 
ben profile image
Ben Halpern

Vertical align-related issues can be so frustrating.

Collapse
 
hichdima_dev profile image
Hichdima_dev

global img { display: block; max-width: 100% } is always at the top of my css file

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
davejs profile image
David Leger • Edited

Seriously tho... are you actually trying to be helpful? 🙄

Thread Thread
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
minescz profile image
minescz

@christiankaindl thanks so much for this article even though it's been a few years since it was published, trust me, it's really helpful, I couldn't find any other documentation that explains it, I also looked for this issue in stackoverflow and nothing really concrete was mentioned, I am a beginner in all this, this literally saved my project, since I couldn't find any official document that has this type of info.

Collapse
 
ultrox profile image
Marko Vujanic

@christiankaindl Thanks so much for this article, I never knew about this. I guess I never thought about what does it really mean to be inline.

I was on rollercoaster first cursing the world, to realizing this makes sense :D

Collapse
 
prisny02 profile image
นี่ด็อกซอนไง

I always use float: left to the image to fix this issue. But still not a solid sulution.

Collapse
 
christiankaindl profile image
Christian Kaindl

Yeah, float: left is a fast fix but it can also brak a layout very easily. A good alternative can be display: inline-flex instead of using float.

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
eoloughlin profile image
Loxy

Had this yesterday. The kind of bizarre issue that is so easy to fix and yet so illusive.