图像标签关闭 [英] Image tag closing

查看:194
本文介绍了图像标签关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何关闭HTML中的图片标签?

 < img src =#>< / img> 

 < img src =#/> 

 < img src =#> 


解决方案

按照以下HTML5标准: http://www.w3.org/TR/html-markup/syntax.html#
$ b


开始标记包含以下部分,正如以下
顺序:

>


  1. <
  2. 元素的标签名称。

  3. 可选地,一个或多个属性,每个属性前面必须有一个或多个空格字符。 / li>
  4. 可选地,包含一个或多个空格字符。

  5. 也可以是/字符,只有元素为空元素时才可以存在。

  6. 一个>字符。


code> img 是一个 void 元素,因此第5部分将适用于 a'/'字符的警告,

=.../>

所以,您 可能 省略第5部分即关闭/,因此这也是有效的:

 < img id =... src =...> 

更进一步的规格说:


Void元素只有一个开始标签;对于void元素,不得指定结束标签

所以,不需要结束标签。


How to close image tag in HTML?

<img src="#"></img>

or

<img src="#" />

or

 <img src="#">

解决方案

As per this HTML5 standard: http://www.w3.org/TR/html-markup/syntax.html#void-element

Start tags consist of the following parts, in exactly the following order:

  1. A "<" character.
  2. The element’s tag name.
  3. Optionally, one or more attributes, each of which must be preceded by one or more space characters.
  4. Optionally, one or more space characters.
  5. Optionally, a "/" character, which may be present only if the element is a void element.
  6. A ">" character.

The img is a void element and hence the part #5 would apply with a caveat that "a '/' character, which may be present..."

<img id="..." src="..." />

And so, you may omit the part #5 i.e. the closing "/", and hence this is also valid:

<img id="..." src="..." >

Further down the spec says:

Void elements only have a start tag; end tags must not be specified for void elements.

So, no end tag is required.

这篇关于图像标签关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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