tags:

views:

66

answers:

5

i'm trying to insert an image in a div container using css and html, but it doesn't display any image.

html code:

<div id="wrapper">
<div id="quoteContainer">
 <span class="start_img"></span>
</div>
</div>

css:

#quoteContainer {
    color: #898989;
    background:#F9F9F9;
    border: solid 1px #ddd; 
    border-radius:10px;
    -moz-border-radius: 10px;
    -webkit-border-radius: 10px;
    box-shadow: 0px 0px 10px #888;
    -moz-box-shadow: 0px 0px 10px #888;
    -webkit-box-shadow: 0px 0px 10px #888;
    margin:65px auto;
    padding:15px;
    width:500px;

}

    .start_img {
     background: url(image/img1.png); 
     border: dotted 2px black;
     width:200px;
     height:20px;
    }

apart from the img, not even the border shows. i tried using the <img> tag in html to insert the image inside the div, that doesn't work either. is there anything wrong with the code?

+9  A: 

That's because a span is an inline element by nature, and won't accept arbitrary width nor height values. You'll have to either make it a block/inline-block element (Wasn't there a question about that yesterday?) or fill it with content.

It would most certainly work with an img element if you set the src property.

And, as already said yesterday, if you want your empty elements to display properly throughout browsers, make sure you fill them with at least an &nbsp;

Pekka
+3  A: 

The span element, being an inline element, cannot take a width and a height.

Did you try the following?

<div id="wrapper">
<div id="quoteContainer">
 <img src="image/img1.png" />
</div>
</div>
Daniel Vassallo
i tried that. it didn't work. i tried with a <div> tag as well filling the image through css. that didn't work either.
fuz3d
@fusion: The only reasons I can think of why using `<img>` may not work would be: 1) The path to the image is incorrect. 2) The style of the `wrapper` or `quoteContainer` `<div>` is preventing the image from being displayed.
Daniel Vassallo
i've edited the code. please check it out.
fuz3d
i figured it out. it was because of the javascript function which was calling the quotecontainer after every 10sec [i had set it that way].thanks a lot for the pointer, anyway.
fuz3d
+2  A: 

You need to change the span from being inline:

.start_img {
     background: url(image/img1.png); 
     border: dotted 2px black;
     width:200px;
     height:20px;
     display:inline-block;
    }

And put something in the span.

<span class="start_img">&nbsp;</span>
Kyle Sevenoaks
+1  A: 

if you have in a big content & and they floated give that divs & span float/

When an element cant take width, you have to try add;

display:block; 

to your class/

and for your divs;

display:block;
width:204px;
height:24px;

but as Pekka said;

<img src="#" class="blabla" alt="img" />

works fine//

spielersun
i tried everyone's suggestion, it didn't work.
fuz3d
A: 

Maybe you don't have the image uploaded properly? Double check that and all of your syntax because these all seem like reasonable and sensible explanations. You could just do:

<div id="wrapper">
<div id="quoteContainer">
 <span class="start_img"><img src="http://www.whereYouStoreimage.com/link/to/image/imag.png"/&gt;&lt;/span&gt;
</div>
</div>
LightningWrist
@lightingwrist, thanks for the reply. but i worked out the answer. please see Daniel Vassallo answer.
fuz3d