Reputation: 25
I have an external css file, linked in to the html. If i apply style for example a div class it Works, but when i apply style for html, body etc. it doesn't work. Why is that?
This is the CSS code:
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;
}
This code only work, when i put a style tag into the html file.
And this is the HTML:
<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
</body>
</html>
Upvotes: 0
Views: 641
Reputation: 303
html {
background: url('https://www.bottega7.com/media/filer_public_thumbnails/filer_public/f5/98/f5986e4f-b733-4ab8-aa3b-0d474d257464/copertina_img-theme-park_v2.jpg__1200x700_q100_crop_subsampling-2_upscale.jpg') no-repeat center center fixed;
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
}
h1 {
color: #fff;
}
<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<h1>Test</h1>
</body>
</html>
Also make sure you have the correct style.css and img path. It is only in path problem and not others.
Upvotes: 0
Reputation: 2311
You should fix the image url, for example consider the following directories:
, the style.css
code is
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;
}
add the following code to the header of the page e.g. index.html
<link rel="stylesheet" href="css/style.css">
Upvotes: 0
Reputation: 11
I also had this problem, but when I removed some of the letters from the link, it worked out. Remove (css/) and let the (style.css) only be in the place, so it should work.
Upvotes: 1
Reputation: 66
check the image if you have have a html file and folder css which holds the css file like the given image then you can add the css to html like the given link tag.
< link rel="stylesheet" href="css/base.css">
now you can write whatever css you want under the css/base.css file and you have to use the url directory property like
url("../image/image.png")
whick says that one level up and find the image directory and add image.png to this html document
Upvotes: 0