tags:

views:

15

answers:

2

hi,

I have a sequence of couples of elements. (.div1, .div2) I'm using position:relative attribute on .div2 to move it a bit on top and right with respect to div1.

However .div1 elements have different content and heights, so the relative positioning of .div2 is not consistent (they sometimes are too high, sometimes too low).

.div2 {
    position:relative;
    left:200px;
    top:-300;   
}

thanks

Updated: The HTML code is very simple

<div class="div1"> blabla </div>
<div class="div2"> blabla </div>
A: 

This question will be very difficult to answer without some example markup.

Would you be able to solve the problem by specifying a bottom and a right, instead? Are those numbers more stable?

DDaviesBrackett
I've updated my question with the markupI'm going to have the same issue using bottom (this time the height of div2 make its position unstable)
Patrick
ups sorry, actually bottom doesn't have any effect on the position of div2. I tried both bottom:0; and bottom:800px; and it is the same..
Patrick
A: 

If ".div2" is inside ".div1", you could use position:relative on .div1, and the position:absolute on .div2, to force it to get it's position relative to .div1.

A bit counterintuitive, but it works.

jeanreis
ok thanks. Unluckily this is not true, they are one after the other one.
Patrick
I've actually adopted your solution! But I've used position:relative on the parent of div1 and div2, and I applied position:absolute on both div1 and div2. I hope this is a good cross-browser solution.
Patrick
Ah yes, well thought!
jeanreis