Ads Top

Align Block element Horozontaly in CSS


Use the following code to align block element horizontally

1:  <!DOCTYPE html>  
2:  <html>  
3:  <head>  
4:  <style>  
5:  .center {  
6:      margin: auto;  
7:      width: 60%;  
8:      border: 3px solid #73AD21;  
9:      padding: 10px;  
10:  }  
11:  </style>  
12:  </head>  
13:  <body>  
14:  <h2>Center Align Elements</h2>  
15:  <p>To align block element (like div) horizontally, use margin: auto;</p>  
16:  <div class="center">  
17:    <p><b>Note: </b> margin:auto does not work in IE8, unless a !DOCTYPE is declared.</p>  
18:  </div>  
19:  </body>  
20:  </html>  


Powered by Blogger.