You do not need to float your div to the right - you just need to align each block next to the other, and you can do this using float: left; .
I have made a consistent decision for you. See below:
Using a class to remove the DRY of your code, I grouped your blocks into a common class with the usual behavior.
See the new CSS:
#wrapper { background-color: grey; height: 200px; width: 500px; } .block { float: left; width: 250px; } #leftDiv { background-color: purple; height: 200px; } #rightDiv { background-color: green; height: 250px; }
And your new HTML:
<div id="wrapper"> <div class="block" id="leftDiv"> <h1>This is my heading</h1> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p> </div> <div class="block" id="rightDiv"> <h1>This is my heading</h1> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p> </div> </div>
Using classes to do common things is good practice to avoid redundancy and future problems.
To see how your code works on jsFiddle, just click here .
source share