(1)HTML并没有要求一定要有<html>, <head>, <body>(XHTML会做校验)
<!DOCTYPE html>
<meta charset=utf-8>
<title>Browsers add html, head, body elements</title>
<p>There is no html, head, body element in the source code but if you check - in any browser - you'll find they've been inserted.</p>
浏览器会正常解析,并自动构建了包含标准标签的DOM树,解析后的DOM树如下:
<!DOCTYPE html>
<html><head><meta charset="utf-8">
<title>Browsers add html, head, body elements</title>
</head><body><p>There is no html, head, body element in the source code but if you check - in any browser - you'll find they've been inserted.</p></body></html>
(2)浏览器如何判断<head>结束<body>开始的呢?
<!DOCTYPE html>
<meta charset=utf-8>
<title>Browsers add html, head, body elements</title>
<vomitingotter>This is in a <vomitingotter> element. (this is, as yet, not officially part of HTML. hurry up, Hixie!) But how does the browser know it should be in the <body>?</vomitingotter>
浏览器遇到不认识的<vomitingotter>就认为是<body>开始,解析后的DOM树如下:
<!DOCTYPE html>
<html><head><meta charset="utf-8">
<title>Browsers add html, head, body elements</title>
</head><body><vomitingotter>This is in a <vomitingotter> element. (this is, as yet, not officially part of HTML. hurry up, Hixie!) But how does the browser know it should be in the <body>?</vomitingotter></body></html>
(3)只要遇到<head>中可识别的Metadata(<base>, <link>, <meta>, <noscript>, <script>, <style>, <template>, <title>)以外的标签就结束<head>,如果你把Metadata写在了后边也不会被自动识别到<head>中。
<!DOCTYPE html>
<viewport>This is the content of a pretend <viewport> element, which in the source is the first line after the DOCTYPE, before the charset declaration or title element. But if you look in any DOM inspector in any browser, you'll see that it's been put in the body.</viewport>
<meta charset=utf-8>
<title>Browsers add html, head, body elements</title>
浏览器遇到不认识的标签<viewport>就认为是<body>开始,<meta>和<title>被解析到了<body>中:
<html><head></head><body><viewport>This is the content of a pretend <viewport> element, which in the source is the first line after the DOCTYPE, before the charset declaration or title element. But if you look in any DOM inspector in any browser, you'll see that it's been put in the body.</viewport>
<meta charset="utf-8">
<title>Browsers add html, head, body elements</title></body></html>
(4)即使你把不该出现在<head>中的标签强制放到<head>里,比如:
<!DOCTYPE html>
<html>
<head>
<viewport>This is the content of a pretend <viewport> element, which in the source is the first line after the DOCTYPE</viewport>
<meta charset=utf-8>
<title>Browsers add html, head, body elements</title>
</head>
<body>
<p>Paragraph in body element</p>
</body>
</html>
浏览器也不认为他们是<head>信息:
<html><head>
</head><body><viewport>This is the content of a pretend <viewport> element, which in the source is the first line after the DOCTYPE</viewport>
<meta charset="utf-8">
<title>Browsers add html, head, body elements</title>
<p>Paragraph in body element</p>
</body></html>
以上使用的浏览器是:Google Chrome 版本:35.0.1916.153。
参考:
http://www.brucelawson.co.uk/2014/why-is-viewport-in-a-meta-tag/
http://www.w3.org/TR/html401/struct/global.html
分享到:
相关推荐
<HEAD> <TITLE>诗词学习</TITLE> </HEAD> <BODY> <P>我是第一段</P> <P>我是第二段</P> <P align="left">左对齐显示<P> <P align="center">居中显示<P> <P align="right">右对齐显示<P> </BODY> </HTML> <HEAD> ...
<body></body>是Html文档的主体部分,在此标志对之间可包含<p>、</p>、<h1>、</h1>、<br>、<hr>等等众多的标志,它们所定义的文本、图像等将会在浏览器的框内显示出来。两个标志必须一块使用。<body>标志中还可以有...
<head> </head> <body> 这是标题 1 这是标题 2 这是段落 这个段落设置了内边距。 </body> </html> 活动2:使用百分比或者像素值设置行间距。 HTML代码如下: <html> <head> </head> <body> 这是拥有...
<body> <div id="top"> <div id="top_text"> <ul> <li><a href="#">联系我们</a></li> <li><a href="#">加入收藏</a></li> <li><a href="#">设为首页</a></li> </ul> </div> </div> <div id="middle"> <div id="logo...
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>"); out.println(" <BODY>"); out.println("<form action='searchServlet' method='post'>"); out.println("<a href='cart'>查看购物车</a><br><br>");...
<modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.4.RELEASE</version> <relativePath/> <!-- ...
<head><title>使用 html 方式</title></head> <body> <h1 align="center"><u>一级标题</u></h1> <p>…其他正文…</p> <h1 align="center"><u>一级标题</u></h1> </body> </html> <html> <head><title>使用 css 方式...
<body> <header> <h1>欢迎来到我的博客</h1> </header> <nav> <ul> <li><a href="#home">主页</a></li> <li><a href="#articles">文章</a></li> <li><a href="#about">关于我</a></li> </ul> ...
charset=GB2312" %><br><br><html><br><head><br><title>CH5 - Login.jsp</title><br></head><br><body><br><br><h2>javax.servlet.http.HttpSession - session 对象</h2> <br><form action=Login.jsp method="POST...
<head> <meta charset="utf-8"> <title>表格 </title> </head> <body> ....... </body> </html> <table border="1"> <tr> <td>品牌</td> <td>型号</td> <td>颜色</td> </tr> <tr> <td>华为</td> <td>mate40pro</td> ...
<HTML><HEAD> <TITLE>动物世界</TITLE> </HEAD> <H1><FONT SIZE=3 COLOR=FORESTGREEN> <B>让我们看看这些可爱的动物</B></FONT></H1> <BODY> <P> <IMG ALIGN=BOTTOM SRC=Animal.jpg>底部对齐</P> <P> <IMG ALIGN=TOP...
<center><p><font size="10px"><B>Practical Quiz 3</B></font></p></center> <form color="#FF00FF"> <center>Login Name:<input type="text"></center><br> <center> Password:<input type="password">...
2、HTML的基本机构(<html><head><title><body>) 3、文档设置标记上-格式标(<br><p><center><pre><li><ul><ol><dl><dt><dd><hr><div>) 4、文档设置标记下-文本标记(<hn><font><b><i><sub><sup><tt><cite><em>...
<head> <meta charset="utf-8" /> <title>Grayscale Canvas Example</title> <script src="modernizr-2010.07.16dev.js"></script> </head> <body> <img src="logo.jpg" id="avatar" title="logo" alt=...
<head> <meta charset="UTF-8"> <script type="text/javascript" src="Clock.js"></script> </head> <body> <canvas width='500' height='500' id='clock'></canvas> </body> <script> initClock('...
基本结构标签: <HTML>,表示该文件为HTML文件 ...</HEAD>,<HEAD>的结束标志 <BODY>,放置浏览器中显示信息的所有标志和属性,其中内容在浏览器中显示. </BODY>,<BODY>的结束标志 </HTML>,<HTML>的结束标志
<head> <meta charset="UTF-8"> <title>文件上传</title> </head> <body> <form action="fileUploadController" method="post" enctype="multipart/form-data"> 上传文件:<input type="file" name="filename"/> ...
<head> <title>添加</title> </head> <body> <div align="center"> <h1> 添加手机信息 </h1> <form action="addphoneAction.jsp" method="post"> <table border="1"> <tr> ...
一款非常漂亮的基于HTML5+Canvas实现的放烟花特效,地面旋转,夜空3D烟花动画特效。
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head> <title>登录页面</title></head><body> <form name="loginForm" method="post" action="judgeUser.jsp"> <table> <tr> <td>用户名:...