"body {background-color}"在HTML中有效,但在CSS中无效

Cur*_*rge 14 html css background-color

能够在内联<style>命令中设置HTML主体的background-color属性,但是在将相同的命令移动到外部样式表时则不能.下面给出一个具体的例子.

在test1.html中,background-color设置为"blue:在HTML中.文件test2.html与test1.html相同,除了<style>命令被注释掉.文件style.css包含背景颜色的规范,也用于<H1>element(用于测试浏览器是否正在读取样式表).

第一次测试在蓝色背景下产生橙色文本.第二次测试产生橙色文本,但是在白色背景下.我在Firefox 21,Chrome 19和IE 9上试过这个; 都给出了相同的结果.

这是怎么回事?任何帮助,将不胜感激.

以下是三个示例文件:

test1.html:

<HTML>
<head> <link type="text/css" rel="stylesheet"  href="style.css">
<style type="text/css">
  body {background-color: blue}
</style> 
</head>
<body> <h1>This is a test.</h1> </body> </html>
Run Code Online (Sandbox Code Playgroud)

test2.html:

<HTML>
<head> <link type="text/css" rel="stylesheet"  href="style.css">
<!-- <style type="text/css">
       body {background-color: blue} 
     </style> -->
</head>
<body> <h1>This is a test.</h1> </body> </html>
Run Code Online (Sandbox Code Playgroud)

style.css中:

<style type="text/css">
   body {background-color: green;}
   h1 {color: orange; }
</style>
Run Code Online (Sandbox Code Playgroud)

谢谢!

Aru*_*mar 14

不要<style type="text/css"></style>在style.css中使用