is< img>元素块级或内联级? [英] Is <img> element block level or inline level?
问题描述
我已经读过< img>
元素的行为。如果正确,有人可以用示例解释吗?
I've read somewhere that <img>
element behaves like both. If correct, could someone please explain with examples?
推荐答案
这是真的,他们都是 - 块元素。
It's true, they are both - or more precisely, they are "inline block" elements. This means that they flow inline like text, but also have a width and height like block elements.
在CSS中,您可以将元素设置为
In CSS, you can set an element to display: inline-block
to make it replicate the behaviour of images*.
图像和对象也称为替换元素,因为它们可以复制图像*的行为。
Images and objects are also known as "replaced" elements, since they do not have content per se, the element is essentially replaced by binary data.
*请注意,浏览器在技术上使用 display:inline
(如开发者工具中所见),但是他们对图像给予特殊处理。他们仍然遵循 inline-block
的所有特征。
* Note that browsers technically use display: inline
(as seen in the developer tools) but they are giving special treatment to images. They still follow all traits of inline-block
.
这篇关于is< img>元素块级或内联级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!