父元素百分比 line-height设置文字居中

当父元素设置高度为百分比的时候 line-height的值自然也就不能是定值 不能用绝对的px值 ,但是给line-height设置百分比,实际上这个百分比是根据字体大小计算的,还是无法得出具体的百分比,所以遇到这种情况只能另辟蹊径,有两种解决办法:
1.给父元素设置display:flex;align-items:center;justify-content:center;
2.给父元素设置displa:table;需要居中的元素 设置 display:table-cell;vertical-align:middle;

猜你喜欢

转载自blog.51cto.com/13550695/2107638