Float right and position absolute doesn't work together

trbaphong picture trbaphong · Jul 4, 2012 · Viewed 181.6k times · Source

I want a div to be always at the right of its parent div, so I use float:right. It works.

But I also want it to not affect other content when inserted, so I use position:absolute.

Now float:right doesn't work, my div is always at the left of its parent div. How can I move it to the right?

Answer

eivers88 picture eivers88 · Jul 4, 2012

Use

position:absolute; right: 0;

No need for float:right with absolute positioning

Also, make sure the parent element is set to position:relative;