Align Div Horizontally and Responsive in HTML5

Let’s start with the HTML code:

  1. <div class="main">  
  2.     <div class="first"> First Div </div>  
  3.     <div class="second"> Second Div </div>  
  4.     <div class="third"> Third Div </div>  
  5.     <div class="clear"> </div>  
  6. </div>  
Here I’ve three Div’s and now am going to apply style to it.
  1. main  
  2. {  
  3.     width: 100 % ;  
  4. }.first  
  5. {  
  6.     width: 30 % ;  
  7.     height: 100 px;  
  8.     background: #CCC;  
  9.     float: left;  
  10. }.second  
  11. {  
  12.     width: 30 % ;  
  13.     height: 100 px;  
  14.     background: green;  
  15.     float: left;  
  16. }.third  
  17. {  
  18.     width: 30 % ;  
  19.     height: 100 px;  
  20.     background: red;  
  21.     float: left;  
  22. }.clear  
  23. {  
  24.     clear: both;  
  25. }  
I’ve set the width of main Div as 100% - full width. And the width of the three div’s are also set in percentage. This property is used to make the design responsive.

The output will be the following:

output
Here you can find the fiddle. : https://jsfiddle.net/saranyatr/12tsq8bd/.

Ebook Download
View all
Learn
View all