“body {background-color}”在HTML中工作,但不在CSS中工作 [英] "body {background-color}" works in HTML but not in CSS

查看:119
本文介绍了“body {background-color}”在HTML中工作,但不在CSS中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

能够为内嵌的< style> 命令
设置HTML主体的background-color属性,但是当相同的命令移动到外部样式表。下面给出一个具体的例子


在test1.html中,背景颜色在HTML中设置为blue:。文件test2.html与test1.html相同,只是< style> 命令被注释掉了.File style.css包含背景颜色的规范,也包含< H1> 元素(测试浏览器真的是
阅读样式表)。



第一个测试会在蓝色背景下产生橙色文本,第二个测试产生橙色
文本,但在白色背景下,我已经在Firefox 21,Chrome 19和
IE 9上尝试了这一点,所有结果都一样。



什么是如果有任何帮助,将不胜感激。



以下是三个示例文件:

test1.html:

 < HTML> 
< head>< link type =text / css =stylesheet href =style.css>
< style type =text / css>
body {background-color:blue}
< / style>
< / head>
< body>< ; h1>这是一项测试。< / h1> < /体> < / HTML>

test2.html:

 < HTML> 
< head> < link type =text / css =stylesheethref =style.css>
<! - < style type =text / css>
body {background-color:blue}
< / style> - >
< / head>
< body> < h1>这是一项测试。< / h1> < /体> < / HTML>

style.css:

 < style type =text / css> 
body {background-color:green;}
h1 {color:orange; }
< / style>

谢谢!

解决方案