Html html没有链接css
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18422974/
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
html not linking css
提问by Telmo Vaz
I'm having an issue with linking html and Css and have no idea why. I'm doing everything like the book and tutorials says. However, I'm not getting to do the external configuration of css.
我在链接 html 和 Css 时遇到问题,不知道为什么。我正在做书和教程所说的一切。但是,我不会进行 css 的外部配置。
This is the code(just a test):
这是代码(只是一个测试):
<!DOCTYPE html>
<html lang = "eng">
<head>
<meta name="viewport" content="width=device-width; initial-scale=1.0">
<title>title</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link rel="stylesheets" type="text/css" href="/styles.css">
</head>
<body>
<h1>test</h1>
</body>
</html>
and CSS:
和 CSS:
body {
background-color:#CCCCCC;
}
h1 {
color:#0000EE;
}
Maybe I miss something, because when I do internal css (within my html code with ) it goes ok and the web browser is able to read that. It seems like the html is not linked with css, but it's even on the same folder so the path shouldn't be the problem.
也许我错过了一些东西,因为当我执行内部 css(在我的 html 代码中)时,它会正常工作并且 Web 浏览器能够读取它。看起来 html 没有与 css 链接,但它甚至在同一个文件夹中,所以路径应该不是问题。
I'm using Linux and Aptana Studio.
我正在使用 Linux 和 Aptana Studio。
I've searched a lot the last 2 hours and cannot find where the mistake is.
我在过去 2 小时内进行了大量搜索,但找不到错误所在。
回答by Charaf JRA
I invite you to read this article Absolute and Relative Paths
我邀请你阅读这篇文章绝对路径和相对路径
Then we pass to your code:
然后我们传递给您的代码:
<link rel="stylesheets" type="text/css" href="/styles.css">
<link rel="stylesheets" type="text/css" href="/styles.css">
Should be :
应该 :
<link rel="stylesheet" type="text/css" href="styles.css">
<link rel="stylesheet" type="text/css" href="styles.css">
Your styles.css
should be in the same folder as your html file.
您styles.css
应该与您的 html 文件位于同一文件夹中。
To verify that you have an error , check Consoleof your browser,you will be noticed that your file doesn't exist(404 error).
要验证您是否有错误,请检查浏览器的控制台,您会注意到您的文件不存在(404 错误)。
An other way to make your css working is to integrate it inside your page without separation:
使您的 css 工作的另一种方法是将其集成到您的页面中而无需分离:
Example:
例子:
<style type='text/css'>
body {
background-color:#CCCCCC;
}
h1 {
color:#0000EE;
}
</style>
回答by Jeff
If the other suggestions don't work, you can try re-saving the HTML and CSS sheets with "UTF-8" encoding and declare UTF-8 encoding in the HTML under the <head>
with <meta charset="utf-8>"
如果其他建议不起作用,您可以尝试使用“UTF-8”编码重新保存 HTML 和 CSS 表,并在<head>
with下的 HTML 中声明 UTF-8 编码<meta charset="utf-8>"
回答by DAve Dori
If all the above not working:
如果以上所有方法都不起作用:
1- Make sure you have no inline/internal CSS > Delete all style code from the Html page (it ll prevent external csslink)
1- 确保您没有内联/内部 CSS > 从 Html 页面中删除所有样式代码(它会阻止外部 css链接)
回答by Taranjit Randhawa
I had the same problem correct the correct directory structure solved my problem. This is a good visualiton on how to organize your directory structure.
我有同样的问题更正正确的目录结构解决了我的问题。这是关于如何组织目录结构的一个很好的可视化。
http://rosebusch.net/jeff/miscellaneous/tree.html
http://rosebusch.net/jeff/miscellaneous/tree.html
That is, the index.html
folder is on the same level as the CSS folder. If you want to put index.html
in a HTML folder, to link to the CSS folder you would have to backout first by linking href="../css/stylesheet.css"
. The ".."
will take you up a level.
也就是说,该index.html
文件夹与 CSS 文件夹在同一级别。如果您想放入index.html
一个 HTML 文件夹,要链接到 CSS 文件夹,您必须首先通过链接href="../css/stylesheet.css"
. 该".."
会带你升了一级。
回答by John Conde
Make sure style.css
is in your root web directory since that is where you are calling it from
确保style.css
在您的根 Web 目录中,因为这是您从中调用它的地方
回答by Carlos Reyes
Don't put the / in front of styles.css and make sure they are in the same folder.
不要将 / 放在 style.css 的前面,并确保它们在同一个文件夹中。
回答by Stuart Miller
The rel attribute should just have stylesheet in it, singular not plural as well
rel 属性中应该只有样式表,单数而不是复数
回答by Michael Giovanni Pumo
Try this instead:
试试这个:
<!DOCTYPE html>
<!-- Language was wrong? -->
<html lang = "en">
<head>
<meta name="viewport" content="width=device-width; initial-scale=1.0">
<title>title</title>
<meta name="description" content="">
<meta name="keywords" content="">
<!-- Check the path to the file - I made it relative to where the HTML is -->
<!-- Correct the rel attribute's value too -->
<link rel="stylesheet" type="text/css" href="./styles.css">
</head>
<body>
<h1>test</h1>
</body>
</html>