My browser shows that the <img>
tag is an inline tag. Numerous answers in Stack says that span does not accept an height property because it's an inline tag.
How can <img>
do that ? Why isn't it rather an inline-block element ?
Inline element properties: The height of an inline element is the height of the content. The width of an inline element is the width of the content. The height and width of an inline element cannot be set in CSS. You cannot set the height and width of block-level elements in CSS.
behaves as an inline-block element as it allows other images in same line i.e. inline and also we can change the width and height of the image and this is the property of a block element. Hence, provide both the features of inline and block elements.
The historical reason to define height/width in tags is so that browsers can size the actual <img> elements in the page even before the CSS and/or image resources are loaded. If you do not supply height and width explicitly the <img> element will be rendered at 0x0 until the browser can size it based on the file.
Paragraphs are block-level elements, which means that they block off a whole line for themselves, and images are inline elements, which means they will automatically be placed next to one another on the same line.
<img>
tag is not strictly an inline element, but a inline-replaced element.
In a nutshell, it means that <img>
(and other elements, as <video>
or, <object>
if you still use it), has intrinsic dimensions. So CSS can handle those dimensions (and other properties, such as margins). Because <img>
is an inline tag, that is replaced by its own source file (well, it's still an inline element).
Some doc about that :
Funny fact (I guess) : you can't override (or simply handle) inline-replaced behavior to "normal" inline behavior on those elements with CSS (when it works when you set it to inline-block or block or whatever you want). See this example : http://jsfiddle.net/s8apbbof/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With