是 <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 中,您可以将元素设置为 display: inline-block
以使其复制图像的行为*.
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
.
这篇关于是 <img>元素块级还是内联级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!