css flex布局实现文字垂直居中
生活随笔
收集整理的這篇文章主要介紹了
css flex布局实现文字垂直居中
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在沒使用flex之前,垂直居中最常用的方法就是將容器的line-height設置為和容器一樣的高度,但這種方法很生硬,每次需要更改容器高度的時候都需要考慮line-height,使用以下這種方法可以實現自適應的垂直居中!
<style>.innner {display: flex;background-color: #ea4d22;height: 100px;/* line-height: 100px; *//* text-align: center; */justify-content: center;flex-direction: column;}.innner2 {display: flex;background-color: #18a0c2;height: 100px;/* line-height: 100px; */text-align: center;justify-content: center;flex-direction: column;}.innner3 {background-color: #20e64b;height: 100px;text-align: center;} </style> <div class="innner">垂直居中示例</div> <div class="innner2">垂直水平居中示例</div> <div class="innner3">水平居中示例</div>總結
以上是生活随笔為你收集整理的css flex布局实现文字垂直居中的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: js正则表达式 验证手机号,email地
- 下一篇: 计算机毕业设计及论文-原创(基于Spri