可以< header>替换< head>在HTML? [英] Can <header> replace <head> in HTML?

查看:165
本文介绍了可以< header>替换< head>在HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始阅读有关标题的内容,我在2011年发现了一篇关于SO约会的文章,该文章说< header> 标签是另一种写作方式< div class =header>

I just started reading about headers and I found an article here on SO dating to 2011 which says that the <header> tag is another way of writing <div class="header">.

但是,为了好玩,我尝试了它并用< head> >< header> ,发现我的网站完全没有变化。即使< title> 也会正确显示。

However, just for fun, I experimented with it and replaced <head> with <header> and found no change in my site at all. Even the <title> displays correctly.

因此我的问题。 html5中的< header> 标记是< head> 标记的替代品吗?
如果没有,有人可以提出关于为什么我网站上的内容没有变化的建议吗?

Hence my question. Is the <header> tag in html5 a replacement for the <head> tag? If not, could anyone offer a suggestion on why things haven't changed on my site?

提前致谢。

推荐答案

通常,浏览器对无效的 html 过于宽容。例如,无论您是否有重复的 id ,或者您在<$内有< tr> c $ c>< ul> ,它仍会呈现你的 html ,但最好不要利用它,因为这会导致在稍后的时间点出现意外结果,例如当您编写css或脚本时。

Generally the browsers are way too tolerant to invalid html. For example, regardless of whether you have duplicate id's or you have a <tr> inside a <ul>, It will still render your html, But it's better to not take advantage of it, because this can cause unexpected results in later point of time, for example when you're writing css or scripts.

< header> element是作为 html5 的一部分引入的语义标签之一。

The <header> element is one of the semantic tags introduced as part of html5.

来自MDN -

< header>


HTML < header> 元素代表一组介绍性或导航辅助工具。它可能包含一些标题元素,但也包含其他元素,如徽标,包装部分的标题,搜索表单等。

The HTML <header> Element represents a group of introductory or navigational aids. It may contain some heading elements but also other elements like a logo, wrapped section's header, a search form, and so on.

< a href =https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head =nofollow> < head>


HTML头元素(< head> )提供有关文档的一般信息(元数据),包括其标题和脚本和样式表的链接或定义

The HTML Head Element (<head>) provides general information (metadata) about the document, including its title and links to or definitions of scripts and style sheets

有关您网站的信息例如 title 应该语义进入< head> 标记。

Information about your website such as title should semantically go in the <head> tag.

因此,在< header> 标记中添加有关您网站的信息是语义上不正确的。
如果你不希望你的 html 代码在语义上是正确的,那么你没有使用语义的目的标签(我的意见

So adding the information about your site in a <header> tag is "Semantically" incorrect. If you don't want your html code to be semantically correct, then there's no purpose for you using semantic tags at all (my opinion)

这篇关于可以&lt; header&gt;替换&lt; head&gt;在HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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