css3 transform实现水平和垂直居中

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> html, body { height: 100%; } .wrapper { position: relative; width: 100%; height: 100%; background: url("background.jpg") center no-repeat; background-size: cover; } .wrapper .login { position: absolute; width: 255px; height: 300px; top: 50%; left: 50%; transform: translate(-50%, -50%); background-color: #eee; } </style> </head> <body> <div class="wrapper"> <div class="login"></div> </div> </body> </html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzpfpy.html