我可以在HTML文档的head元素内添加div标签吗? [英] Can I have a div tag inside of the head element in a HTML document?
问题描述
只想知道是否有可能在head元素内使用div标签?
Just want to know if it's possible to have a div tag inside the head element?
推荐答案
否,<div>
不是位于<head>
标记内的有效标记,因为<head>
标记仅用于元数据(例如标题和页面说明),脚本,样式以及其他不希望显示的内容.尽管将它放在<head>
中是可行的,但这样做太可怕了,您不应该将它放在这里(并且规范说这样做不是有效的HTML.谢谢@ t.niese);这是无效的HTML
No, <div>
is not a valid tag to be inside of the <head>
tag, since the <head>
tag is only meant to be for metadata (such as title and page description), scripts, styles, and other stuff which isn't meant to be displayed. Although putting it in the <head>
works, it's horrible to do so, and you shouldn't put it there (and the specification says that doing that is not valid HTML. Thanks @t.niese); it's invalid HTML
此外,对属性值使用"
或'
(在您的情况下为id
)也没有区别,这正是您所喜欢的.是的,使用'
是完全有效的.我喜欢这样做,因为我不必按住档,但这完全取决于您.
Also, there is no difference between using "
or '
for attribute values (such as id
in your case), it's just what you prefer. And yes, using '
is completely valid. I like doing that, since I don't have to hold shift, but it's completely up to you.
这篇关于我可以在HTML文档的head元素内添加div标签吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!