我使用下面的css来定义我的背景:
body
{
background-image: url('background.png');
font-size: 12pt;
font-family: Veranda, Arial, Helvetica, sans-serif;
}图像background.png存储在根目录中,但每当我刷新网页时,背景仍然是白色的。我的导师目前有一份我的文件的副本,并试图自己解决这个问题,尽管这个问题对他来说并不明显。我的完整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>发布于 2010-10-14 18:43:37
CSS文件不应包含
<style type = "text/css">
<!--我假设这会导致解析第一个CSS块( body块)时出错。
发布于 2010-10-14 19:23:52
style.css中不允许使用超文本标记语言
您需要删除<style type = "text/css">、html注释标记<!--以及每个标记的结束标记。
你也不需要在后台url周围加上‘’,它可以写成这样。
background-image: url(background.png);进行这些更改,并假设background.png位于正确的目录中,它将正常工作。
https://stackoverflow.com/questions/3932273
复制相似问题