水平垂直居中方法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <div class=""> <p></p> </div> </body> </html> <style> div { width: 300px; height: 300px; background: #33d; position: relative; } p { position: absolute; width: 100px; height: 100px; background: green; left: 50%; top: 50%; transform: translate(-50%, -50%); /* margin-left: -50px; margin-top: -50px; */ } </style>