+ 1

Can you set an element relative to another relative element?

7th Jul 2021, 1:00 PM
Blake Grass
Blake Grass - avatar
4 Antworten
+ 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)
7th Jul 2021, 6:23 PM
visph
visph - avatar
+ 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
7th Jul 2021, 1:19 PM
Abhay
Abhay - avatar
+ 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)
7th Jul 2021, 6:19 PM
visph
visph - avatar
0
When you say nesting, do you mean like this? <div> <div></div> </div>
7th Jul 2021, 3:38 PM
Blake Grass
Blake Grass - avatar