乐闻世界logo
搜索文章和话题

Is < img > element block level or inline level?

1个答案

1

elements are by default inline-level elements. This means they do not occupy a line by themselves and can be displayed on the same line as other inline elements such as text and links. Although it is an inline element,

can also have width and height properties specified.

Example: Using

in a paragraph:

html
<p>This is an example of text, with an image displayed beside it: <img src="example.jpg" alt="Example image"></p>

In this example, the image will appear on the same line as the text unless the image's width or external styles (such as the display property in CSS) force a line break. However, if you want the image to behave like a block-level element, you can change its display property using CSS:

css
img { display: block; }

After this setting, the image will occupy a line by itself and not appear on the same line as other elements.

2024年8月14日 16:59 回复

你的答案