html - Position absolutely positioned DIV relative to (also absolutely positioned) parent DIV? -


this 1 problem have when i'm fixing layouts. i've got absolutely positioned div, place child-div inside needs absolutely positioned. want child-div behave relative parent... possible? or need create wrap-div?

<div class="container" style="position:relative;">     <div class="parent" style="position:absolute;">          <!-- child div behave relative .container -->         <div class="child" style="position:absolute;"></div>     </div> </div> 

this 'wrapping' solution i'd rather avoid:

<div class="container" style="position:relative;">     <div class="parent" style="position:absolute;">         <div class="wrapper" style="position:relative;">              <!-- child div behave relative .wrapper-->             <div class="child" style="position:absolute;"></div>         </div>     </div> </div> 

an absolutely positioned element positioned respect edges of nearest ancestor not positioned (i.e. not position: static).

since parent element is position: absolute, child positioned respect edges.

so appear asking how behaviour have. comment in first example appears incorrect.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -