views:

1459

answers:

3

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.

+4  A: 
<style>
#div1, #div2 {
   float: left; /* or right */
}
</style>
Calvin
+3  A: 

(excuse the inline styles :))

<div style="float: left;">Left Div</div>
<div style="float: right;">Right Div</div>
Marcel Guzman
+5  A: 

As an alternative way to floating:

<style>
    .wrapper{position:relative;}
    .right,.left{width:50%; position:absolute;}
    .right{right:0;}
    .left{left:0;}
</style>
...
<div class="wrapper">
    <div class="left"></div>
    <div class="right"></div>
</div>

Considering that there's no necessity to position the .left div as absolute (depending on your direction, this could be the .right one) due to that would be in the desired position in natural flow of html code.

Sepehr Lajevardi