is< img>元素块级或内联级? [英] Is <img> element block level or inline level?

查看:125
本文介绍了is< img>元素块级或内联级?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经读过< 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&lt; img&gt;元素块级或内联级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆