html,body區域添加一個水平垂直居中的盒子


 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Document</title>
 6     <style type="text/css" media="screen">
 7         *{
 8             margin: 0;
 9             padding: 0;
10         }
11         html,body{
12             width: 100%;
13             height: 100%;
14         }
15         body{
16             display: flex;justify-content: center;align-items: center;
17         }
18         .box{
19             width: 500px;
20             height: 500px;
21             border: 1px solid #ccc;
22         }
23     </style>
24 </head>
25 <body>
26     <div class="box">
27         
28     </div>
29 </body>
30 </html>

自己經常喜歡寫一些測試代碼,就希望在顯示器的正中顯示該盒子,其實就是這么簡單的一段代碼,還有使用傳統的方式來實現居中的,有時間寫寫


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM