+ 1
Can you set an element relative to another relative element?
4 odpowiedzi
+ 2
but 'absolute' make also the element removed from normal content flow, so if only child of its parent auto computed size should be 0 (at least height)... you should use explicit size to make space for the child (else child will be displayed above -- as a layer -- next content)
+ 2
yes if they have a child parent relationship!
Run the following code,
<style>
div{
height:100px;
width:100px;
}
#first{
background-color:red;
position:relative;
left:100px;
}
#second{
background-color:blue;
position:relative;
left:10px;
}
</style>
<div id="first">
<div id="second"></div>
</div>
but have no idea about how would one set an element relative to other one without nesting them
+ 1
Blake Grass yes, nesting is what you described: one element inside another one...
however, 'position: relative' make an element position relative to himself (to its original position)... to make an element position relative to the nearest positioned parent, you should use 'absolute' rather than 'relative' ^^ (so its position properties -- top, left, bottom, right -- will apply relative to first positioned parent related edges)
0
When you say nesting, do you mean like this?
<div>
<div></div>
</div>