Search code examples
csscss-floatposition

Float right and position absolute doesn't work together


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?


Solution

  • Use

    position:absolute; right: 0;

    No need for float:right with absolute positioning

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