首页
CSS
CSS Flexbox
Flex 容器
Tryit:完美居中
运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <head> <style> .flex-container { display: flex; justify-content: center; align-items: center; height: 300px; background-color: DodgerBlue; } .flex-container > div { background-color: #f1f1f1; color: white; width: 100px; height: 100px; } </style> </head> <body> <h1>Perfect Centering</h1> <p>A flex container with both the justify-content and the align-items properties set to <em>center</em> will align the item(s) in the center (in both axis).</p> <div class="flex-container"> <div></div> </div> </body> </html>