我的 CSS 无法链接到我的 HTML 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19672648/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
My CSS won't link to my HTML file
提问by ChriskOlson
I am trying to build a simple website in Sublime Text Editor 2, however, my CSS file won't link to my HTML file and therefore printing plain text. My HTML code is:
我正在尝试在 Sublime Text Editor 2 中构建一个简单的网站,但是,我的 CSS 文件不会链接到我的 HTML 文件,因此无法打印纯文本。我的 HTML 代码是:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/ xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Christopher Olson</title>
<link href="http://fonts.googleapis.com/css?family=Open+Sans:300,600,700" rel="stylesheet" />
<link rel="stylesheet" href="css/style.css" />
As far as I know, the last line is supposed to link the CSS file.
据我所知,最后一行应该链接 CSS 文件。
This is part of the CSS that I have:
这是我拥有的 CSS 的一部分:
body, input, textarea
{
font-family: 'Open Sans', sans-serif;
line-height: 1.85em;
color: #888;
font-weight: 300;
}
Any ideas to fix? Please help
有什么想法要解决吗?请帮忙
EDIT: I have the tags, I just ran out of room to post it
编辑:我有标签,我只是没有空间发布它
回答by John Conde
Your path your CSS file is probably wrong. If you're sane your CSS directory is in the webroot so your <link>
should probably look like this:
您的 CSS 文件路径可能是错误的。如果你的 CSS 目录在 webroot 中,那么你<link>
应该看起来像这样:
<link rel="stylesheet" href="/css/style.css" />
回答by MarkMoore
Definitely is your link's href incorrect.
绝对是您链接的 href 不正确。
回答by bondjamesbond
The link to your css files will be relative to the location of your html file. If both are int the same directory, then just include the name of the css file, if it is in a folder named "css" and that folder is in the same directory as your html file then you do "css/"
css 文件的链接将与 html 文件的位置相关。如果两者都在同一个目录中,则只需包含 css 文件的名称,如果它位于名为“css”的文件夹中并且该文件夹与您的 html 文件位于同一目录中,那么您执行“css/”
回答by Troncador
I think your href is wrong
我认为你的 href 是错误的
You can tried using a absolute url just like
您可以尝试使用绝对网址,就像
<link rel="stylesheet" href="http://..../css/style.css" />
You can download a very nice plugin for firefox called "firebug" it show you when some resource can't be reach
您可以为 firefox 下载一个非常好的插件,名为“firebug”,它会在无法访问某些资源时向您显示
回答by T0k9sy
It will 100% work if your "call" link is placed within the html file. I'm having the same issue, my only work around is to include the call links in both the .html and .css ball ache, but it works
如果您的“呼叫”链接放置在 html 文件中,它将 100% 工作。我遇到了同样的问题,我唯一的解决方法是在 .html 和 .css ball ache 中包含调用链接,但它有效