11.盒子水平垂直居中.html 650 B

12345678910111213141516171819202122232425262728293031
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. * {
  9. margin: 0;
  10. padding: 0;
  11. }
  12. html,body {
  13. width: 100%;
  14. height: 100%;
  15. }
  16. #box {
  17. width: 200px;
  18. height: 200px;
  19. background: #f00;
  20. position: absolute;
  21. top: 50%;
  22. left: 50%;
  23. margin-top: -100px;
  24. margin-left: -100px;
  25. }
  26. </style>
  27. </head>
  28. <body>
  29. <div id="box"></div>
  30. </body>
  31. </html>