首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法加载网页背景图像

无法加载网页背景图像
EN

Stack Overflow用户
提问于 2010-10-14 18:40:07
回答 2查看 1.6K关注 0票数 0

我使用下面的css来定义我的背景:

代码语言:javascript
复制
body
{
    background-image: url('background.png');
    font-size: 12pt;
    font-family: Veranda, Arial, Helvetica, sans-serif;
}

图像background.png存储在根目录中,但每当我刷新网页时,背景仍然是白色的。我的导师目前有一份我的文件的副本,并试图自己解决这个问题,尽管这个问题对他来说并不明显。我的完整html和css如下:

HTML:

代码语言:javascript
复制
<!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:

代码语言:javascript
复制
<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>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-10-14 18:43:37

CSS文件不应包含

代码语言:javascript
复制
<style type = "text/css">
<!--

我假设这会导致解析第一个CSS块( body块)时出错。

票数 2
EN

Stack Overflow用户

发布于 2010-10-14 19:23:52

style.css中不允许使用超文本标记语言

您需要删除<style type = "text/css">、html注释标记<!--以及每个标记的结束标记。

你也不需要在后台url周围加上‘’,它可以写成这样。

代码语言:javascript
复制
background-image: url(background.png);

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3932273

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档