首页 > Web开发 > 详细

css 利用flex居中对齐

时间:2020-04-14 13:17:11      阅读:100      评论:0      收藏:0      [点我收藏+]
 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="utf-8">
 5         <title></title>
 6         <style>
 7             
 8             .box1{
 9                 width: 800px;
10                 height: 500px;
11                 border: 4px red solid;
12                 
13                 /* 设置弹性容器 */
14                 display: flex;
15                 /* 设置主轴居中 */
16                 justify-content: center;
17                 /* 设置侧轴居中 */
18                 align-items: center;
19             }
20             
21             .box2{
22                 
23                 background-color: #bfa;
24             }
25             
26         </style>
27     </head>
28     <body>
29         
30         <div class="box1">
31             <div class="box2">aaaaaaaaa</div>
32         </div>
33         
34     </body>
35 </html>

技术分享图片

 

 

内容,只需要父元素设置

/* 设置弹性容器 */
display: flex;
/* 设置主轴居中 */
justify-content: center;
/* 设置侧轴居中 */
align-items: center;

css 利用flex居中对齐

原文:https://www.cnblogs.com/fsg6/p/12697216.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!