【问题标题】:Background-image inside div not showing updiv内的背景图像未显示
【发布时间】:2013-09-19 02:09:21
【问题描述】:

所以我在这个网站上工作,我展示了我想要的东西。 在处理较低的页面横幅后,突然一切都消失了,我只剩下正文中的背景图像。

你能弄清楚为什么 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>

对不起,如果这是一个非常基本的问题,我对此有点陌生。

【问题讨论】:

标签: html css image background positioning


【解决方案1】:

#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;
}

或者只是在div 中粘贴一个img 标签而不是使用background-image,这样也可以。

【讨论】:

  • 我试过了,结果还是一样?我只是智障还是真的搞砸了?
  • 不,我也不能让它在 jsFiddle 中工作。 :S 注意:如果我在 div 标签之间输入文本,它会显示在适当的位置,而如果我将图像放在样式表中或 div 标签之间,它将不会显示。我可以确保图像在我检查过的文件夹中。
  • 由于某种原因它现在可以工作了。哪里错了?我不知道,但发生了一些变化,现在它工作正常。感谢您的帮助。
  • 不用担心,很高兴能帮到您。 :)
【解决方案2】:

尝试使用以下语法

#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;
}

希望能解决问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-11
    • 1970-01-01
    • 1970-01-01
    • 2010-12-19
    • 1970-01-01
    • 2015-03-15
    • 2011-09-24
    • 1970-01-01
    相关资源
    最近更新 更多