html – 如何使用flexbox垂直对齐div页面

前端之家收集整理的这篇文章主要介绍了html – 如何使用flexbox垂直对齐div页面前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
参见英文答案 > Why is percentage height not working on my div? 2个
以下内容不是将div与浏览器选项卡中的文本垂直对齐(它正确水平对齐): @H_502_3@<div style="height: 100%; display: flex; align-items: center; justify-content: center;"> <div> Some vertical and horizontal aligned text </div> </div>

怎么了?

解决方法

问题在于您给父容器的高度.高度:100%不占整个高度.将其改为100vh或类似

这是更新的Demo

@H_502_3@.container{ height: 100vh; display: flex; align-items: center; justify-content: center; } @H_502_3@<div class="container"> <div> Some vertical and horizontal aligned text </div> </div>

猜你在找的HTML相关文章