Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS: How to set position absolute of a span inside a relative-position-div which contains [closed]

Tags:

html

css

position

I have this code:

<br><br><br>
<div style="position: relative; background: #000000; height: 400px;">
    <span style="position: absolute; top: 0; left: 0; display: block; background: #FF0000; width: 100px; height: 100px;">
    </span>
</div>

It works, all I need is the span is located by absolute position compare to the div container.

But when I add an image inside of the div:

<br><br><br>
<div style="position: relative; background: #000000; height: 400px;">
    <img src="FabledLeviathan.png">
    <span style="position: absolute: top: 0; left: 0; display: block; background: #FF0000; width: 100px; height: 100px;">
    </span>
</div>

The span does not display at [0, 0] comparing to the container div as it did before. It now displays under the image. How should I fix this?

like image 386
xx3004 Avatar asked Nov 04 '11 05:11

xx3004


1 Answers

You have a small typo in the <span>'s style.

You have a : after the word absolute. Should be a ;

<div style="position: relative; background: #000000; height: 400px;">
    <img src="FabledLeviathan.png">
    <span style="position: absolute; top: 0; left: 0; display: block; background: #FF0000; width: 100px; height: 100px;">
    </span>
</div>
like image 133
Strelok Avatar answered Sep 30 '22 14:09

Strelok