html文档头对css影响
最近开发中,遇到一个问题。body{font-size:12px}对<td></td>内文字不起作用。html文件的完整格式如下
<!--
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
-->
<html>
<head>
<title>font size test</title>
<meta http-equiv="keywords" content="enter,your,keywords,here" />
<meta http-equiv="description" content="A short description of this page." />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<!--
<style type="text/css">
body{
font-size:48px;
/*对td内元素无效,如果无html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
*/
}
</style>
-->
<link rel="stylesheet" href="font.css" type="text/css"/>
</head>
<body>
<p>
p元素内文字
</p>
<hr/>
<table>
<tr>
<td>td内文字</td>
</tr>
</table>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
-->
<html>
<head>
<title>font size test</title>
<meta http-equiv="keywords" content="enter,your,keywords,here" />
<meta http-equiv="description" content="A short description of this page." />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<!--
<style type="text/css">
body{
font-size:48px;
/*对td内元素无效,如果无html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
*/
}
</style>
-->
<link rel="stylesheet" href="font.css" type="text/css"/>
</head>
<body>
<p>
p元素内文字
</p>
<hr/>
<table>
<tr>
<td>td内文字</td>
</tr>
</table>
</body>
</html>
允许效果如下
去掉文件头注释后
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>font size test</title>
<meta http-equiv="keywords" content="enter,your,keywords,here" />
<meta http-equiv="description" content="A short description of this page." />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<!--
<style type="text/css">
body{
font-size:48px;
/*对td内元素无效,如果无html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
*/
}
</style>
-->
<link rel="stylesheet" href="font.css" type="text/css"/>
</head>
<body>
<p>
p元素内文字
</p>
<hr/>
<table>
<tr>
<td>td内文字</td>
</tr>
</table>
</body>
</html>
允许效果
不带文件头时浏览器是怎么解析html文档的呢?