问题描述
我在这里不知所措.我已经搜索了数十个网站,试图找到解决该问题的方法,但是我还没有找到一种对我有帮助的解决方案.
I'm at the last of my wits here. I've searched through dozens of websites trying to find the answer to this issue, but I have yet to find a solution that helps me.
这是HTML的顶部,链接到我的CSS文件:
Here is the top section of my HTML, linking to my CSS file:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
<title>Sample Page</title>
</head>
由于某些原因,当我在浏览器中预览.html文件时,未考虑我的CSS代码.
For some reason, when I preview my .html file on my browsers, my CSS code is not taken into account.
仅需澄清一点,我已经确保以下不是造成我问题的原因:
Just to clear things up a bit, I've already made sure the following are not the reasons for my issues:
- 我的CSS代码在样式中的HTML中时效果很好标签.我将其放入自己的.css文件后,它才停止工作.
- .css文件上没有
< style>
标记. - 我其余的HTML格式正确.我有
</html>
标记和< body>
标记. - 我已经在Chrome和Firefox甚至是另一台计算机的Chrome上测试了此页面.我什至尝试过以管理员身份运行它们.
- 我已检查确认我的浏览器未设置为Quirks模式.
- 我尝试了多个DOCTYPE标头,但都没有任何工作迹象.
- .css名称正确,文件位置正确.index.html和style.css都在同一个文件夹中.
- 我以不同的顺序,不同的格式尝试了这些代码行,甚至尝试了其他人的代码,但没有任何效果.
- 我已经在浏览器中检查了页面的源代码,然后单击style.css链接直接指向该文件.
我获得的唯一线索是,我在Chrome浏览器的页面上单击了检查元素",然后选中了资源"标签,该HTML位于 Frames>(index.html)> index下.html ,然后在 Frames>(index.html)> Stylesheets> style.css 下找到CSS.如果单击index.html,则正文为空白,但是如果单击style.css,则正文为一点中文文本.
The only lead I've gotten is that I clicked "Inspect Element" on my page in Chrome and checked the "Resources" tab, where the HTML is found under Frames>(index.html)>index.html and the CSS is found under Frames>(index.html)>Stylesheets>style.css. If I click index.html, the body is blank, but if I click style.css, the body is, strangely enough, a bit of Chinese text.
这是我尝试过的style.css示例:
Here is a sample of a style.css I've tried:
body
{
background-color: yellow;
}
即使CSS这样简单,它仍然无法正常工作.
Even with the CSS as simple as this, it still won't work.
请帮助.
编辑: http://i.imgur.com/SgoFkvw.png
请阅读我的文章.它们在同一个文件夹中.不同的路径在Chrome的检查元素"模式下,而不在我的文件夹中.
推荐答案
Jozef Dúc wrote in the comments (1, 2):
这就是为我解决的问题.
This is what solved it for me.
这篇关于无法将CSS链接到HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!