我最近开始学习Web编程的绳索,在阅读一本书时,我展示了两种将.html文件链接到.css文件的方法.
方法1:
<link rel="examplesheet" href="myexamplesheet.css" type="text/css"
media="screen" />
Run Code Online (Sandbox Code Playgroud)
方法2:
<style type="text/css" media="screen">
@import url(examplesheet.css);
</style>
Run Code Online (Sandbox Code Playgroud)
正如一些问题所指出的那样,它们都应该工作,但方法1对我的程序不起作用,即使方法2工作正常.
我的程序很简单.它看起来像这样:
<title> Title Site</title>
<link rel="canvas" href="canvas.css" type="text/css"
media="screen" />
<style type="text/css" media="screen">
@import url(canvas.css);
</style>
<p> We have black text.</p>
<p class="green"> And then we have Green Text.</p>
<p class="warning"> Warning. Warning. Warning.</p>
Run Code Online (Sandbox Code Playgroud)
如果方法1是唯一的那个,则文本将无法正确显示.在Internet Explorer中,它只显示默认文本.但在Firefox和Chrome中,它实际上显示了方法1的错误:
XML解析错误:文档元素之后的垃圾位置:file:/// C:/Users/Zolani/AppData/Local/Temp/sample.xhtml第3行,第1列:
我不确定为什么这只出现在这两个浏览器上.一个网页,详细说明差异谈到把它在文本的头上.我试过,使用"head"标签,它仍然无法正常工作.
现在我可以继续使用方法2并愉快地使用我的程序,但我仍然想知道为什么方法1似乎不能正常工作.有任何想法吗?
注意:我使用的是xhtml而不是html.
该rel属性必须是stylesheet为了让浏览器将其解释为样式表.
<link rel="stylesheet" href="canvas.css" type="text/css"
media="screen" />
Run Code Online (Sandbox Code Playgroud)