2010-10-14 40 views
0

页面背景图片将不会加载

body 
{ 
    background-image: url('background.png'); 
    font-size: 12pt; 
    font-family: Veranda, Arial, Helvetica, sans-serif; 
} 

图像0​​保存在根目录下,但每当我刷新网页,背景仍然是白色的。我的教练目前有一份我的档案,并试图自己弄清楚,尽管这个问题对他来说并不明显。我全HTML和CSS如下:

HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 

<html> 
<head> 
<meta http-equiv="content-type" content = "text/html charset = utf-8" /> 
<link rel = stylesheet href = "style.css" type = "text/css" media = screen> 
<title> 
Title 
</title> 
</head> 

<body> 
<div id = "wrapper"> 
    <div id = "leftsidebar"> 
     <h3> Navigation </h3> 
    </div> 

    <div id = "content"> 
     <h1> Heading 1 </h1> 
     <h2> Heading 2 </h2> 

     <p align = "justify"> Paragraph 1.</p> 

     <p align = "justify"> Paragraph 2 </p> 

     <p align = "justify"> Paragraph 3 </p> 
    </div> 
</div> 
</body> 

</html> 

CSS:

<style type = "text/css"> 
<!-- 
body 
{ 
    background-image: url('background.png'); 
    font-size: 12pt; 
    font-family: Veranda, Arial, Helvetica, sans-serif; 
} 

div#wrapper 
{ 
    width: 80%; 
    margin-top: 50px; 
    margin-bottom: 50px; 
    margin-left: auto; 
    margin-right: auto; 
    padding: 0px; 
    border: thin solid #000000; 
} 

div#header 
{ 
    padding: 15px; 
    margin: 0px; 
    text-align: centre; 
} 

div#leftsidebar 
{ 
    width: 25%; 
    padding: 10px; 
    margin-top: 1px; 
    float: left; 
} 

div#content 
{ 
    margin-left: 30%; 
    margin-top: 1px; 
    padding: 10px; 
} 

div#footer 
{ 
    padding: 15px; 
    margin: 0px; 
    border-top: thin solid #000000; 
} 
--> 
</style> 
+0

是你的background.png还在根目录下吗?我通常不会以这种方式推荐使用相对路径(以/(root)开头)。你也可以使用firebug来查看img是否有负载......另外,链接元素中属性和值之间的奇怪空白是什么? – Hannes 2010-10-14 10:45:18

回答

2

CSS文件不应该包含

<style type = "text/css"> 
<!-- 

我认为导致解析第一个CSS块(body之一)的错误。

1

HTML是不允许在你的style.css

您需要删除<style type = "text/css">中,HTML注释标记<!--,显然每个结束标记。

你也不需要围绕背景网址,它可以这样写。

background-image: url(background.png); 

进行这些更改,并假设background.png位于正确的目录中,它将起作用。