2016-10-19 58 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>