Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Positioning a div inside a div without affecting layout

Tags:

css

css-float

I have a div (div1) that has its position, width, height, everything all set, and it is set externally, so I can't know ahead of time what those values are.

Inside and at the top of div1 is another div (div2). I want div2 to float on the right of div1 without affecting the following information in div1.

I can add the attribute position:absolute and get div2 to float and not affect the contents, however, I cannot get it to float on the right, even when applying float:right.

like image 645
steveo225 Avatar asked Sep 02 '26 19:09

steveo225


1 Answers

If I understand correctly:

First, apply position: relative to your div1.

As it "won't work" when you have both float: right and position: absolute on your div2, you should replace the float: right rule with right: 0.

like image 120
thirtydot Avatar answered Sep 05 '26 12:09

thirtydot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!