css如何实现快速居中?
简单来说快速居中,就是给它的父级设置display: flex;属性,自身设置margin: auto;的属性
例如
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> * { margin: 0px; padding: 0px; } html,body { width: 100%; height: 100%; display: flex; } .allitem{ width: 100px; height: 100px; background-color: yellow; margin: auto; } .all { width: 500px; height: 500px; background-color: red; margin: auto; display: flex; } </style> </head> <body> <div class="all"> <div class="allitem"> </div> </div> </body> </html>