1. ホーム
  2. html

[解決済み] Is <img> element block level or inline level?

2022-04-15 04:05:55

Question

I've read somewhere that <img> element behaves like both. If correct, could someone please explain with examples?

How to solved?

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.

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.

* Note that browsers technically use display: inline (開発者ツールに見られるように) しかし、彼らは画像に特別な扱いを与えているのです。彼らはまだ inline-block .