Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

div with absolute position behind the normal flow

i am trying to get a div to be my background and am using absolute positioning to achieve it. everything works fine except for the fact that it appears above anything in the normal flow and fiddling with z-indexes does absolutely nothing.

<div id="blind">
    <div id="blindbackground"></div>
    <div id="blindcontainer">
        <div class="loader">
            <img class='loader' src="/img/loader.gif"/>
        </div>
    </div>
    <div id="blindclosecontainer">
       <img id='blindclose' src="/img/close.gif"/>
    </div>
</div>

and this is the css:

#blind{
    position :absolute;
    width:100%;
    z-index: 2;
    border-bottom: 1px silver solid;
}
#blindclosecontainer{
    text-align: right;
}

#blindbackground{
    position:absolute;
    top:0;
    width:100%;
    height:100%;
    background-color: white;
    filter:alpha(opacity=60);
    opacity:0.6;
}
#blindcontainer{
    margin:auto;
    width:500px;
    background-color: white;
    padding:10px;
}

.loader{
    margin: auto;
    width:18px;
    margin-top:10px;
    margin-bottom: 5px;
}
like image 295
vasion Avatar asked May 11 '10 07:05

vasion


People also ask

Can a div be position absolute and relative?

Clearly, nothing can be absolute and relative at the same time. Either you want the element to position itself based on another ancestor's position or based on the page flow.

How do you position an absolute element?

Absolute An element with position: absolute is removed from the normal document flow. It is positioned automatically to the starting point (top-left corner) of its parent element. If it doesn't have any parent elements, then the initial document <html> will be its parent.

Can I use display flex with position absolute?

If you position a flex item absolutely, it no longer participates in the flex layout. This means any flex properties on the item become moot. You can remove them if you like.


1 Answers

Add position:relative; to the #blindcontainer and #blindclosecontainer classes.

like image 89
Guffa Avatar answered Oct 13 '22 21:10

Guffa