外部 CSS 不起作用
External CSS don't work
我有一个外部 css 文件,链接到 html。如果我为 div class 应用样式,它会起作用,但是当我为 html、body 等应用样式时,它不起作用。这是为什么?
这是 CSS 代码:
html {
background: url(img/bc.jpg) no-repeat center center fixed;
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
}
只有当我将样式标签放入 html 文件时,此代码才有效。
这是 HTML:
<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
</body>
</html>
检查图像,如果你有一个 html 文件和文件夹 css,其中包含与给定图像一样的 css 文件,那么你可以将 css 添加到 html喜欢给定的 link 标签。
<
link rel="stylesheet" href="css/base.css">
现在你可以在 css/base.css 文件下写任何你想要的 css 并且你必须使用 url 目录 属性 像
url("../image/image.png")
whick 说上一级并找到图像目录并将 image.png 添加到此 html 文档
我也有这个问题,但是当我从 link 中删除一些字母时,它就解决了。
删除 (css/) 并让 (style.css) 只在该位置,所以它应该可以工作。
您应该修复图像 url,例如考虑以下目录:
- /img/bc.jpg
- /css/style.css
- index.html
,style.css
代码为
html {
background: url(../img/bc.jpg) no-repeat center center fixed;
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
}
将以下代码添加到页面的 header 例如index.html
<link rel="stylesheet" href="css/style.css">
我有一个外部 css 文件,链接到 html。如果我为 div class 应用样式,它会起作用,但是当我为 html、body 等应用样式时,它不起作用。这是为什么?
这是 CSS 代码:
html {
background: url(img/bc.jpg) no-repeat center center fixed;
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
}
只有当我将样式标签放入 html 文件时,此代码才有效。
这是 HTML:
<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
</body>
</html>
检查图像,如果你有一个 html 文件和文件夹 css,其中包含与给定图像一样的 css 文件,那么你可以将 css 添加到 html喜欢给定的 link 标签。
< link rel="stylesheet" href="css/base.css">
现在你可以在 css/base.css 文件下写任何你想要的 css 并且你必须使用 url 目录 属性 像
url("../image/image.png")
whick 说上一级并找到图像目录并将 image.png 添加到此 html 文档
我也有这个问题,但是当我从 link 中删除一些字母时,它就解决了。 删除 (css/) 并让 (style.css) 只在该位置,所以它应该可以工作。
您应该修复图像 url,例如考虑以下目录:
- /img/bc.jpg
- /css/style.css
- index.html
,style.css
代码为
html {
background: url(../img/bc.jpg) no-repeat center center fixed;
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
}
将以下代码添加到页面的 header 例如index.html
<link rel="stylesheet" href="css/style.css">