Generally speaking, float
is a relative positioning statement, since it specifies the position of the element relative to its parent container (floating to the right or left). This means it's incompatible with the position:absolute
property, because position:absolute
is an absolute positioning statement. You can either float an element and allow the browser to position it relative to its parent container, or you can specify an absolute position and force the element to appear in a certain location. Specifically, an element with position:absolute
will be placed at whatever offset you specify (with left
, right
, top
, or bottom
) from the position of its nearest ancestor (containing element) with a position
property, regardless of whether it has a float
property or not. If it doesn't have any ancestors with a position
property, it will be placed at your specified offset from the edge of the screen.
If you want an absolutely-positioned element to appear on the right side of its parent div
, you can use position: absolute; right: 0;
-- as long as the parent div
has a position property such as position:relative
. If the parent div
doesn't have a position property, though, this won't work, and you'll need to stick to float:right
.