June 28, 2012

Why isn't this image showing?

Question by sab

I made a header image, but for some reason I can’t get it to appear from CSS.

Here’s a screenshot:
enter image description here

The header is in the same image directory as the index.html file. The background image is appearing, but not this header. I typed the header twice in the HTML as a div to test it in two different spots to see if it is working, but for some reason it is not showing up, I don’t get it lol.

Thanks.

#header {
        background-image:url('../emailheader.png');
        width:100%;
        height:100%;
        background-repeat:no-repeat;

 } 

<div id="header"></div>

Here’s an example of it. But I am not sure why it doesn’t work.

Answer by Rab Nawaz

DEMO

You need provide height OR it will be dependent on the height of the inner content, which 0

 #header {
            background-image:url('http://i.imgur.com/ncTiy.png');
            width:100%;
            background-repeat:no-repeat;
            height:200px;
     } 

Answer by Starx

On seing the screenshot of the code. I found two problems.

  1. There is NO stylesheet attached on the first place
  2. header is used to identify two different elements. (Also mentioned by Blaster)

However, the main reason why it is not showing up in tinkerbin, is because the div neither contains any elements nor has a fixed dimensions. Check this update of your bin.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!