2016-10-19 61 views
1

为什么当我在本地桌面上启动文件时,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; 
} 

我答应接受帮助我,最让请调试代码,我的答案。感谢您的帮助!

回答

1

有一些语法错误:

  1. 加上引号的链接
  2. 删除URL之间的空间和(

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; 
 
}
<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>

+0

它的工作空间删除!我不知道删除一个空间使它工作。我之前使用过不同的文本编辑器,并且在放置空间时仍然有效。我猜这个空间不是正确的代码...... :( –

+0

别担心,我接受了你的答案。如果你认为我的问题有助于你学习,请将它投票! –

0

不需要在报价下添加图片网址。

问题是错误的URL。图片网址中有空格。 BEST-网站之间

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

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; 
 
}
<!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>