I am trying to get a background image for my web page. I have a link to an external style sheet, which works fine (the CSS applies), but when I try to get the background image using background-image it doesn't show the result. I have tried both absolute and relative URLs

HTML:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="generator" content="CoffeeCup HTML Editor (www.coffeecup.com)">
        <meta name="created" content="Wed, 26 Mar 2014 04:01:34 GMT">
        <meta name="description" content="">
        <meta name="keywords" content="">
        <title>Welcome to CSS</title>
        <link rel="stylesheet" type="text/css" href="welcome.css" />
    </head>
    <body></body>
</html>

CSS:

body{
    background-image:url('C:\Users\Neo\Documents\CoffeeCup Software\My
Website\Files\images.jpg');
    background-repeat:repeat-x;
}  
有帮助吗?

解决方案

You can not set absolute path from your locally. you can set absolute path only live web page. following way,

 BODY { background-image: url(http://www.bg.com/pinkish.gif) }

another way set relative path. I assume your root Website folder

 __My Website
      |__Files
          |__images.jpg
      |__welcome.css
      |__welcome.html

It's relative to the style sheet, but I'd recommend making the urls relative to your url, base on above strutted set relative path on following way,

 background-image:url('Files/images.jpg');

其他提示

Try this:

background-image:url('Files/images.jpg');
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top