css就可以让模态框内容盒子水平上下居中

来源:互联网 发布:atheros无线网卡 linux 编辑:程序博客网 时间:2024/05/17 01:45

原文出处:http://www.w3cfuns.com/notes/18019/54eda2ad873b00b0958746627731e2b6.html (有Demo)

<!DOCTYPE html><html lang="zh-CN"><head><meta charset="utf-8"><meta name="keywords" content="" /><meta name="description" content="" /><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"><meta name="format-detection" content="telephone=no, email=no"/><meta name="apple-mobile-web-app-capable" content="yes" /><meta http-equiv="Cache-Control" content="no-siteapp" /><title>demo</title><!--[if lt IE 9]>      <script src="//cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>      <script src="//cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script><![endif]--></head><style type="text/css">.modelWrap{        position: fixed;        top: 0;        left: 0;        width: 100%;        height: 100%;        background: rgba(0,0,0,.5);display: -webkit-flex;/*设置父元素盒子的,这样内部盒子就会水平居中,上下居中。*/-webkit-justify-content:center;/*设置父元素盒子的,这样内部盒子就会水平居中,上下居中。*/-webkit-align-items:center;/*设置父元素盒子的,这样内部盒子就会水平居中,上下居中。*/}.modelInn{background: rgba(0,0,0,.8);border-radius: 4px;color: #fff;padding: 4px;}</style><body>    <div class="modelWrap">    <div class="modelInn">    这是一个水平,上下居中的模态框    </div>    </div></body></html>


0 0
原创粉丝点击