What is the best way to right align and left align two div tags on a web page horizontally next to each other? I would like an elegant solution to do this if possible.
Using float and marginThe left div is styled with width:50% and float:left – this creates the green colored div that horizontally covers half of the screen. The right div is then set to margin-left:50% – this immediately places it to the right of the left div.
The most common way to place two divs side by side is by using inline-block css property. The inline-block property on the parent placed the two divs side by side and as this is inline-block the text-align feature worked here just like an inline element does.
<div style="float: left;">Left Div</div> <div style="float: right;">Right Div</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With