盒子居中
Posted lzhflzjx
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了盒子居中相关的知识,希望对你有一定的参考价值。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <style> .father { width: 300px; height: 300px; display: flex; } .child { margin: auto; } .father1 { width: 300px; height: 300px; position: relative; } .child1 { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); } .father2 { width: 300px; height: 300px; display: flex; justify-content: center; align-items: center; } .child2 {} </style> <body> <!-- flexbox布局 --> <div class="father"> <div class="child"> qweeeeeeeeeee </div> </div> <!-- 子绝父相 --> <div class="father1"> <div class="child1"> qweeeeeeeeeee </div> </div> <!-- flex布局 --> <div class="father2"> <div class="child2"> qweeeeeeeeeee </div> </div> </body> </html>
以上是关于盒子居中的主要内容,如果未能解决你的问题,请参考以下文章