CSS样式-position为absolute的情况下如何居中

<!DOCTYPE html> <html lang="en"> <head>     <title>Document</title>     <style type="text/css">         div {             width: 300px;             height: 300px;             background-color: #f00;             position: absolute;             left: 50%;             /* 用width/2 */             margin-left: -150px;

 

            top: 50%;             /* 用height/2 */             margin-top: -150px;                          /* 当position为absolute时,用下面auto这种方式进行居中,不再起作用 */             /* margin: 0 auto; */         }     </style> </head> <body>     <div></div> </body> </html>
上一篇:谈谈final finally finalize区别


下一篇:Java中 final finally finalize有什么区别?(小白留给自己的笔记)