简体   繁体   English

Meta标签解释:http-equiv和charset

[英]Meta tags explained: http-equiv and charset

Which is best? 哪个最好? And what is the difference? 有什么区别?

<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

or 要么

<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

Another thing, I see that Viewport meta tags and meta http-equiv tags do not get the /> closing tags as charset and other meta tags have...why is that? 另一件事,我看到Viewport元标记和元http-equiv标签没有得到/>结束标签作为charset和其他元标签有...为什么?

Thank you 谢谢

The second one is better, since it's more concise. 第二个更好,因为它更简洁。 It was standardized that way in HTML5. 它在HTML5中以标准化方式标准化。

As for the tags ending in /> : It makes no difference what tag it is. 对于以/>结尾的标签:它与什么标签无关。 No tag has to close like that in HTML5. 没有标签必须像HTML5中那样关闭。 In the olden days of XHTML, all these tags had to close like that, since XHTML is related to XML. 在XHTML的早期, 所有这些标签都必须这样关闭,因为XHTML与XML有关。

So, the takeaway is thus: 因此,外卖是这样的:

  1. Use an HTML5 doctype: <!DOCTYPE html> - Isn't that just nice and simple? 使用HTML5 doctype: <!DOCTYPE html> - 这不是很简单吗?
  2. Definitely use <meta charset="utf-8"> - More concise, more betterererererer... 绝对使用<meta charset="utf-8"> - 更简洁,更好的选择...
  3. No need to close your tags with /> 无需使用/>关闭标记

Reference : http://www.w3schools.com/html5/tag_meta.asp 参考: http//www.w3schools.com/html5/tag_meta.asp

HTML 4.01: meta http-equiv="content-type" content="text/html; charset=UTF-8" HTML 4.01:meta http-equiv =“content-type”content =“text / html; charset = UTF-8”
HTML5: meta charset="UTF-8" HTML5:meta charset =“UTF-8”

so the 2nd one is small(html5) and latest 所以第二个很小(html5)和最新的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM