Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
702 views
in Technique[技术] by (71.8m points)

html - Background-image inside div not showing up

So I was working on this site and I had the displaying how I was wanting. After working on a lower page banner all of a sudden everything disappeared and all I was left with was the background Image in the Body.

Can you figure out why the topImage id does not display? It is frustrating as hell to see it work one second and then not the other:

<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>

Sorry if this a really basic question, I am kind of new at this.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

#topImage doesn't have a height set, and no elements inside it which would give it a height.

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

Or just stick an img tag inside the div instead of using background-image, that would work as well.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...