Align divs on one line and center horizontally - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Div Align

Description

Align divs on one line and center horizontally

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">
#wrapper {<!--  ww w . j  a va 2 s . c o m-->
   background-color:Chartreuse;
}

#container1 {
   border:3px dashed yellow;
   margin:auto;
   width:301px;
   overflow:auto;
}

#box1,#box2,#box3 {
   height:100px;
   width:100px;
   box-sizing:border-box;
}

#box1 {
   border:2px solid blue;
   float:left;
}

#box2 {
   border:2px solid pink;
   float:left;
}

#box3 {
   border:2px solid WhiteSmoke;
   float:left;
}
</style> 
 </head> 
 <body> 
  <div id="wrapper"> 
   <div id="container1"> 
    <div id="box1"> 
     <p>Box 1</p> 
    </div> 
    <div id="box2"> 
     <p>Box 2</p> 
    </div> 
    <div id="box3"> 
     <p>Box 3</p> 
    </div> 
   </div> 
  </div>  
 </body>
</html>

Related Tutorials