盒子垂直居中,水平居中实现例子
<!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></div> </body> </html> <style> body { margin: 0; } div { position: absolute; width: 200px; height: 200px; left: 50%; top: 50%; margin-left: -100px; margin-top: -100px; background-color: red; } </style>
可以使用更简单的方式
div { position: absolute; width: 200px; height: 200px; left: 50%; top: 50%; transform: translate(-50%, -50%); background-color: red; }
标签:居中,top,50%,position,margin,css,200px From: https://www.cnblogs.com/dming4/p/17573198.html