Aligning two div's next to each other using CSS

I have been asked this question several times - How to align two DIV's next to each other using CSS. Here's a simple solution that I have been using for quite a while now:


<html xmlns="http://www.w3.org/1999/xhtml">


<head runat="server">


    <title></title>


    <style type="text/css">


    div.Outer {


        width: 350px;


        border:dashed 1px black;


        position: relative;


        clear: both;


        }


 


        div.InnerLeft {


        width: 50%;


        position: relative;


        background: #CCCCCC;        


        float: left;


        }


 


        div.InnerRight {


        width: 49%;


        position: relative;


        background: #AAAAFF;        


        float: right;


        }


    </style>


</head>


<body>


    <form id="form1" runat="server">


    <div class="Outer">


        <div class="InnerLeft">


        Lorem Ipsum Lorem Ipsum Lorem Ipsum


        Lorem Ipsum Lorem Ipsum Lorem Ipsum


        Lorem Ipsum Lorem Ipsum Lorem Ipsum


        Lorem Ipsum Lorem Ipsum Lorem Ipsum


        Lorem Ipsum Lorem Ipsum Lorem Ipsum


        </div>


        <div class="InnerRight">


        Lorem Ipsum Lorem Ipsum Lorem Ipsum


        Lorem Ipsum Lorem Ipsum Lorem Ipsum


        Lorem Ipsum Lorem Ipsum Lorem Ipsum


        Lorem Ipsum Lorem Ipsum Lorem Ipsum


        Lorem Ipsum Lorem Ipsum Lorem Ipsum


        </div>


    </div>


    </form>


</body>


</html>




OUTPUT

11 comments:

  1. This will only work if the text in the left and the text in the right box have the same length? Or err I?

    ReplyDelete
  2. you have no idea how grateful i am. thanks a ton

    ReplyDelete
  3. Thank you VERY much. I'm not an expert with CSS, and this has really saved me a lot of time.

    ReplyDelete
  4. Thank you! This thing helps me alot.

    ReplyDelete
  5. clean & easy => thanks

    ReplyDelete
  6. Exactly what I needed. Thank you.

    ReplyDelete
  7. Hi, this works wonderfully, until I specify sizes.

    For instance:

    div.InnerLeft {
    margin-right:450px;
    margin-left:0px;
    margin-top:0px;
    margin-bottom:0px;

    position: relative;

    background: #CCCCCC;

    float: left;

    }



    div.InnerRight {

    width: 425px;

    position: relative;

    background: #AAAAFF;

    float: right;

    }

    ReplyDelete
  8. Thank you, it works smoothly. It is a fantastic idea to place div tags!

    ReplyDelete
  9. thank you, this saved me time

    ReplyDelete
  10. I want to Thank you allot.
    I was stressing out because it didn't work out for me, but your code saved my @ss.


    Kudo's!

    ReplyDelete
  11. Superb! Thanks a lot! Really wanted this & finally got it!!

    ReplyDelete