我的 HTML 文件没有连接到我的 CSS 文件。为什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16462139/
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 HTML file isn't connecting to my CSS file. Why?
提问by Akhil
I am not being able to connect my CSS to my HTML file. I put the code below in my head at the top of my HTML file. I used the code on this website to connect my CSS to HTML: http://w3schools.com/tags/tag_link.asp
我无法将我的 CSS 连接到我的 HTML 文件。我把下面的代码放在我的 HTML 文件的顶部。我使用本网站上的代码将我的 CSS 连接到 HTML:http: //w3schools.com/tags/tag_link.asp
This is my HTML file so far:
到目前为止,这是我的 HTML 文件:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="theme.css">
</head>
<body id="whole-background">
<h1>Akhil Sharma</h1>
<p>Official Website</p>
</body>
</html>
and this is my css:
这是我的 css:
#whole-background
{
background-color: #0099FF;
}
Someone please tell how I can fix this problem.
有人请告诉我如何解决这个问题。
回答by Baronth
Save a file called theme.cssin the same directory of the html page, with your css rules
在 html 页面的同一目录中保存一个名为theme.css的文件 ,其中包含您的 css 规则
#whole-background
{
background-color: #0099FF;
}
回答by Cam
To solve these kinds of Problems I highly recommend using Firebug. While you are using firebug you can debug all kinds of problems. One major problem, why is my CSS not linked, or is it and I didnt code it correctly. You can open firebug. Select the CSS TAB
为了解决这些问题,我强烈推荐使用Firebug。当您使用 firebug 时,您可以调试各种问题。一个主要问题,为什么我的 CSS 没有链接,或者是我没有正确编码。你可以打开萤火虫。选择 CSS 选项卡
And see all CSS that are linked. You can also look inside console to see what error codes come up, they are very detailed and save you allot of time.
并查看所有链接的 CSS。您还可以查看控制台内部以查看出现的错误代码,它们非常详细,可以为您节省大量时间。
This is to help you with figuring out these kinds of problems. You dont necessarily have to use link btw.
这是为了帮助您解决此类问题。顺便说一句,您不一定必须使用链接。
<style type="text/css" src="theme.css"></style>
Works just as good.
效果一样好。
回答by Maloric
Firstly, self close your link tag, like so:
首先,自我关闭您的链接标签,如下所示:
<link rel="stylesheet" type="text/css" href="theme.css" />
Next, make sure that your stylesheet (theme.css) is located in the same folder as the html file you are saving. It it is elsewhere, such as in a subfolder called "styles" then you would have to edit the path like so:
接下来,确保您的样式表 (theme.css) 与您保存的 html 文件位于同一文件夹中。它在其他地方,例如在名为“styles”的子文件夹中,那么您必须像这样编辑路径:
<link rel="stylesheet" type="text/css" href="styles/theme.css" />