Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Placing two divs at same horizontal level

Tags:

html

css

I need to put two div elements at the same horizontal level. Doing the way I have done makes the second one get displayed under the first. I want to place them in a way that they cross over each other while transition.

Edit 1- Here when the button is pressed to swap their classes, divs move up and down.

#aaidi,#aaidi3 {
-webkit-transition: margin-left 1s ease-in-out;
-moz-transition: margin-left 1s ease-in-out;
-o-transition: margin-left 1s ease-in-out;
transition: margin-left 1s ease-in-out;
}
.left {
margin-left: 45%;
border: 1px solid green ;
width: 20px;
height: 4px;
background: #FF0000;
} // similar for right with margin-left:55%
......
        <tr>
           <td colspan=3>
              <div id="aaidi" class="left">
              </div>
              <div id="aaidi3" class="right">
              </div>
           </td>
        </tr> // after this there is a button pressing whom changes the class of both divs. 
like image 239
Sumit Sinha Avatar asked Apr 05 '12 16:04

Sumit Sinha


2 Answers

You can achieve this using the float property:

<style type="text/css">
    div.container {
        margin: 15px;   
    }
    div.left, div.right {
        float: left;
        padding: 10px;    
    }
    div.left {
        background-color:orange;    
    }
    div.right {
        background-color: yellow;    
    }
</style>

<div class="container">
    <div class="left">Left</div>
    <div class="right">Right</div>
</div>

See this jsFiddle for a demonstration. Here's the output:

enter image description here

like image 135
James Johnson Avatar answered Sep 22 '22 06:09

James Johnson


Use a span, or you can set the style to display:inline-block

like image 41
Justin Pihony Avatar answered Sep 18 '22 06:09

Justin Pihony