常用居中类:flex-container-center
效果图——
代码:
实例
<!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>居中</title> </head> <body> <style> .flex-container-center { display: flex; display: -webkit-flex; width: 80%; height: 300px; border: 1px solid cadetblue; } .flex-container-center div { width: 50%; height: 100px; border: 1px solid cornflowerblue; margin: auto; } </style> <h5>项目在容器内绝对居中</h5> <div class="flex-container-center"> <div> 这是容器内的项目 </div> </div> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例