<style> .flex-mask { display: flex; position: fixed; z-index: 1; top: 0; left: 0; bottom: 0; right: 0; align-items: center; // 垂直居中 justify-content: center; // 水平居中 background: rgba(0,0,0,.5); } .flex-box { width: 500px; height: 300px; background-color: #fff; border-radius: 10px; } </style> <!-- 元素 --> <p class="flex-mask"> <p class="flex-box"></p> </p>
<style> .transform-box { position: fixed; z-index: 2; top: 50%; left: 50%; width: 300px; height: 150px; background-color: red; border-radius: 10px; transform: translate(-50%, -50%); } </style> <p class="transform-box"></p>
以上就是设置元素水平、垂直居中有哪两种方式 的详细内容,更多请关注Gxl网其它相关文章!
查看更多关于设置元素水平、垂直居中有哪两种方式的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did72044