I am having trouble with element stacking in a HTML page. I need to get span (class=“class_span”) to have a higher stacking order than div (class=“class_div”) with border. I have tried to change the z-index but with no luck. I know that I should not use absolute position, but the page is dependent on it, sorry. How can I accomplish this?
HTML:
<ul>
<li>
<div class="class_div">
</div>
<span class="class_span">
<a href="google.com">google</a>
</span>
</li>
</ul>
CSS:
.class_div{
position: absolute;
border: 100px solid;
width:100px;
height:50px;
left:0px;
}
.class_span{
float: left;
}
Add
position: relativeto the span so that you can applyz-indexon it. Note that thez-indexof your span must be higher than that of thedivso that it appears above thediv:Example
Edit:
As an alternative to
float: left, you might consider usingposition: absoluteand setleftto0px:You may need to set the
topas well, and it may also be necessary to set a parent element’spositiontorelativeso that the span can be positioned relative to that parent element.