div内的背景图像没有出现

时间:2013-09-14 13:43:55

标签: html css image background positioning

所以我正在这个网站上工作,我展示了我的想法。 在一个较低的页面横幅上工作后,突然间一切都消失了,而我留下的只是身体中的背景图像。

你能弄明白为什么topImage id不显示吗?看到它工作一秒而不是另一个是令人沮丧的:

<style>
   body
   {
   background-image:url("images/Background.gif");
   background-repeat:repeat-y;
   background-attachment:fixed;
   background-position:center top;
   }

   #topImage
   {
   position:absolute;
   background-image:url("images/Top-Banner.gif");
   background-repeat:repeat-x;
   width:100%;
   top:0px;
   left:0px;
   }
</style>

<body>

    <div id="topImage"></div>

</body>

很抱歉,如果这是一个非常基本的问题,我对此很新。

2 个答案:

答案 0 :(得分:8)

#topImage没有高度设置,并且里面没有任何可以给它增加高度的元素。

#topImage
{
  position:absolute;
  background-image:url("images/Top-Banner.gif");
  background-repeat:repeat-x;
  width:100%;
  height: 100px; /* Change to the height you need */
  top:0px;
  left:0px;
}

或者只是将img标记放在div内,而不是使用background-image,这样做也可以。

答案 1 :(得分:0)

尝试使用以下语法

#topImage
{
  position:absolute;
  background-image:url("../images/Top-Banner.gif");
  background-repeat:repeat-x;
  width:100%;
  height: 100px; /* Change it to auto if you need to div to adjust automatically according to contents inside it */
  top:0px;
  left:0px;
}

希望能够解决问题

相关问题