html5 img is not a block-level element. img is an inline element and is also a replacement element. It has built-in width and height attributes, so the img tag can set the width and height. img is an inline replacement element. Height, width, padding, and margin are all available, and the effect is equal to that of block elements.
The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.
<img />
Basic use of tagsBrowser support
<img>
TagTag definition and usage instructions
<img>
Tag defines an image in an HTML page <img>
The tag has two required attributes: src and alt<img />
What exactly is it<img />
Is it an inline element or a block-level element? <img />
The tag does not occupy an exclusive line, so it is an inline element, which is no problemSince it is an inline element, why can the width and height be set?
<img />
The label is a replacement element and has built-in width and height attributes, so It can be set, see below for detailed explanation. From the characteristics of the element itself, it can be divided into non-replaceable elements and replaceable elements
Element-related MDN explanation
Irreplaceable element
(X)HTML
Most elements are non-replaceable elements, that is, their content is directly displayed to the user (such as a browser)<h1>I am the title</h1>
Replaceable elements
<img>
tag. However, if you view the (X)HTML code, you cannot see the actual content of the image; and For example, depending on the type attribute of the <input>
tag, it is decided whether to display an input box or a radio button, etc. <img>, < in HTML input>,
are all replacement elements. These elements often have no actual content, that is, an empty element <img src="tigger.jpg"/>
、<input type=" submit" name="Submit" value="Submit"/>
Belongs to replaceable elements
At the same time Has the characteristics of inline elements, inline blocks, and block-level elements
and
height, which can be set
and
height of
<img>, it will be displayed according to its intrinsic size, which is when the image is saved. Width and height
is an inline replacement element.
height/width/padding/margin are all available. The effect is equal to the block element
html video tutorial"
The above is the detailed content of Is img in html5 a block-level element?. For more information, please follow other related articles on the PHP Chinese website!