position two divs next to each other, one of them is centered in the container of both divs - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:2 Column

Description

position two divs next to each other, one of them is centered in the container of both divs

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <style id="compiled-css" type="text/css">
#container {<!--from  w  w  w.j  a v a2  s  .co  m-->
   width:100%;
   display:table;
   height:61px;
   color:Chartreuse;
}

#div1 {
   margin-left:auto;
   margin-right:auto;
   width:201px;
   height:51px;
   background-color:yellow;
   display:table-cell;
}

#div2 {
   display:table-cell;
   height:51px;
   background-color:blue;
   margin-right:0;
   float:left;
   width:100%;
}
</style> 
 </head> 
 <body> 
  <div id="container"> 
   <div id="div2"></div> 
   <div id="div1"> 
   </div> 
  </div>  
 </body>
</html>

Related Tutorials