Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to place a z-index div?

i have a main wrapper that has a fixed width of 960px. at the top and very right hand side there is a login button. by pressing this button it will be opened a div layer directly below and also in front of the main wrapper. therfor i use the z-index: 1. the problem is that i dont know how to set a fixed position depending from the main wrapper instead of the browser-window width. now when setting left/right- position the div will be placed depending from the whole browser-window width. the main wrapper is placed by 0 auto in case of a larger resolution.

to give an example:

code:

#main {
    width:300px;
    height: 500px;
    background-color: #f23;
    margin: 0 auto;
}
#zindex{
    font-size: 11px;
    width: 50px;
    height: 50px;
    background-color: #dedede;
    position: absolute;
    right: 0;--> will place the div depending from the browser window and not main
}

example

if there is someone who could tell me on how to solve this i really would appreciate.

like image 213
bonny Avatar asked Jan 29 '26 19:01

bonny


2 Answers

#main {
    position:relative
}

Should do the trick.

like image 120
Matthew Darnell Avatar answered Feb 01 '26 11:02

Matthew Darnell


#main {
    width:300px;
    height: 500px;
    background-color: #f23;
    margin: 0 auto;
    position: relative;

}

The position:relative will make any child elements position themselves relative to that, instead of the body.

There's some decent examples of how 'position' works over at barelyfitz.com

like image 44
dotty Avatar answered Feb 01 '26 09:02

dotty



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!