美文网首页
利用Flexbox来实现水平垂直居中

利用Flexbox来实现水平垂直居中

作者: 凌Linny | 来源:发表于2017-03-05 13:36 被阅读0次
<!doctype html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <title>居中</title>
   <style type="text/css">
       .container {
           display: flex;
           justify-content:center;  /*水平居中*/
           align-items:center;   /*垂直居中*/
           width: 200px;
           height: 200px;
           background-color: #ccc;
       }
       .center-p {
           background-color: yellow;
       }
   </style>
</head>
<body>
   <div class="container">
       <div class="center-p">
           flex居中
       </div>
   </div>
</body>
</html>
Paste_Image.png

相关文章

网友评论

      本文标题:利用Flexbox来实现水平垂直居中

      本文链接:https://www.haomeiwen.com/subject/yygsgttx.html