【问题标题】:Body background color and image not showing正文背景颜色和图像未显示
【发布时间】:2013-11-07 07:58:13
【问题描述】:

所以.... 我有一个名为 intro 的文件夹。 该文件夹中同时包含 index.html 和 style.css 文件。在 intro 文件夹中是另一个名为“images”的文件夹,用于存储我将使用的图像。在该文件夹(图像)中有一个名为 background.jpg 的图像

代码如下: HTML

    <!DOCTYPE html>
<html>
<head>
    <link type="text/css" rel="stylesheet" href="style.css"/>
    <title>test</title>
</head>
<body>

    <div id="content">
        <div class="info">
            Want to know more about Dreams?
        </div>

    </div>
</body>

CSS

    /*CSS Style Sheet*/
@font-face

body {
background-color: #080808;
background-image: url(images/background.jpg);
margin: auto;
}


#content {
width: 1000px;
background-color: #080808;
margin-left: auto;
margin-right: auto;
margin-top: 500px;
}

由于某种原因,背景图像和背景颜色没有显示出来。 背景颜色保持白色,图像无处可见。帮忙?

【问题讨论】:

  • 你为什么把@font-face这样单独拿出来?
  • 删除font-face

标签: html css image colors background


【解决方案1】:

您在背景图像的路径上缺少“__”。

两个改变顺序并使用背景而不是背景图像。

 body {        
   background:url("images/background.jpg") no-repeat center;
   background-color:blue;
 }

三个 .png 文件可让您在图像中保持透明背景。

四去掉@font-face

查看此演示http://jsfiddle.net/e85kY/

【讨论】:

  • 谢谢! €font-face 造成了它!
【解决方案2】:

您必须从 HTML 文件的位置映射背景图像。例如,如果图像在您的 intro 文件夹中,而您的 HTML 文件在 intro 中的单独文件夹中,则该文件夹为 ..\image\background.jpg。此外,您的 CSS 中不需要 @font-face

在映射时,要返回一个文件夹,您可以使用.. 来暗示路径中的前一个文件夹。

【讨论】:

  • 谢谢! @font-face 导致了这个问题!
  • 没问题。祝你好运!
猜你喜欢
  • 1970-01-01
  • 2010-12-19
  • 2014-08-07
  • 1970-01-01
  • 2012-05-25
  • 1970-01-01
  • 1970-01-01
  • 2023-04-10
  • 1970-01-01
相关资源
最近更新 更多