为什么css背景图片没有显示

时间:2016-10-19 04:45:55

标签: html css

为什么我在本地桌面上启动文件时没有显示CSS背景图像?这是我的代码:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" text="type/css" href="discovery.css">
<title>Programming Club Official Blog</title>
</head>
<body>
<h1>Programming Club Official Blog</h1>
<p>This is a blog that allows member of the programming club to keep in 
  touch about what we are doing in the club. Feel free to look at the code by pressing Ctrl-U! ~ Nathan Tran</p>
</body>
</html>

我的CSS代码:

html {
background:url (http://smashingyolo.com/wp-content/uploads/2014/05/Best- 
Website-Background-Images10.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
 background-size: cover;
}

我保证接受最能帮助我的答案,请为我调试代码。谢谢你的帮助!

2 个答案:

答案 0 :(得分:1)

有一些语法错误:

  1. 将链接放在引号
  2. 删除网址与(
  3. )之间的空格

    &#13;
    &#13;
    html {
    background:url("http://smashingyolo.com/wp-content/uploads/2014/05/Best-Website-Background-Images10.jpg") no-repeat center center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
     background-size: cover;
    }
    &#13;
    <html>
    <head>
    <meta charset="UTF-8">
    <link rel="stylesheet" text="type/css" href="discovery.css">
    <title>Programming Club Official Blog</title>
    </head>
    <body>
    <h1>Programming Club Official Blog</h1>
    <p>This is a blog that allows member of the programming club to keep in 
      touch about what we are doing in the club. Feel free to look at the code by pressing Ctrl-U! ~ Nathan Tran</p>
    </body>
    </html>
    &#13;
    &#13;
    &#13;

答案 1 :(得分:0)

不需要在引号下添加图片网址。

问题是错误的网址。图像URL中有空格。删除之间的空间 最佳网站

http://smashingyolo.com/wp-content/uploads/2014/05/Best-%20Website-Background-Images10.jpg

&#13;
&#13;
html {
background:url(http://smashingyolo.com/wp-content/uploads/2014/05/Best-Website-Background-Images10.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
 background-size: cover;
}
&#13;
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" text="type/css" href="discovery.css">
<title>Programming Club Official Blog</title>
</head>
<body>
<h1>Programming Club Official Blog</h1>
<p>This is a blog that allows member of the programming club to keep in 
  touch about what we are doing in the club. Feel free to look at the code by pressing Ctrl-U! ~ Nathan Tran</p>
</body>
</html>
&#13;
&#13;
&#13;