css - 居中

初始时居中主要设置 auto, 并设置宽度(对于div).如:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
    <html xmlns="http://www.w3.org/1999/xhtml" lang="zh-cn">  
    <head>  
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />  
    <title>居中div</title>  
    <style type="text/css">  
    .align-center{  
        margin:0 auto;      /* 居中 这个是必须的. */  
        width:500px;        /* 给个宽度 顶到浏览器的两边就看不出居中效果了 */  
        text-align:center;  /* 文字等内容居中 */  
    }  
    </style>  
    </head>  
      
    <body>  
    <div class="align-center">居中div</div>  
    </body>  
    </html>  

 

posted @ 2015-02-03 10:29  wonkju  阅读(153)  评论(0编辑  收藏  举报