Placement of two sections on one horizontal level

I need to put two div elements on the same horizontal level. Doing how I did this makes the second appear below the first. I want to place them so that they cross each other during the transition.

Edit 1- Here , when the button is pressed to replace its 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. 
+5
source share
5 answers

You can achieve this using the property float:

<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 the jsFiddle demo . Here's the conclusion:

enter image description here

+12
source

Use span, or you can set the style todisplay:inline-block

+2

, divs

.float-left{
  float:left;
}

 <div id="aaidi" class="float-left left"></div>
 <div id="aaidi3" class="float-left right"></div>

If the right div is still treated as a "block" element, then it will occupy the entire line. Both elements must be placed or certain widths must be set.

+2
source
+1
source

Just put all the divs to the left if you want them to be near.

Depending on the contents of the div, you may need to assign a width to each class.

0
source

All Articles