div自动居中

    技术2022-05-11  54

    自己做的页面中用到了div,position又设置为了absolute,页面在1024*768分辨率下是没问题的,但换个2048*1096就顶到左上角去了,怎么居中呢?研究了一下,找到种可行的方法。只有在原来基础上稍加改动就行,还是比较理想的。首先要定义两个style,设置好页面属性,然后就是给绝对位置的div外面套两层div,类似 ===================================== <html> <body> <head> <style type="text/css">      body {           background-repeat: repeat-x repeat-y;      background-position: left top;      text-align:center;      }    .container{      margin-left:auto;      margin-right:auto;      width:738px;     }     .layer0{      position: relative;      width: 738px;      height: 40px;          }  </style>   </head> <body> <div id="container" class="container"> <div id="layer0" class="layer0"> ***********your code here**************** </div> </div> </body> </html> ====================================  

    最新回复(0)