xx3004
xx3004

Reputation: 788

How to set position absolute of a span inside a relative-position-div which contains

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

Upvotes: 6

Views: 56855

Answers (1)

Strelok
Strelok

Reputation: 51481

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>

Upvotes: 8

Related Questions