CSS 实现文字垂直居中的 7 种方法

Lenix at 
一、问题描述: 当高度固定或不固定时,单行或多行文本难以实现垂直居中;二、解决方法:1、使用 line-height 属性,将 line-height 设置与元素高度等高。局限性:只适用于单行文本,局限性大。代码:.box { height: 100px; line-height: 100px; white-space: nowrap; } 2.padding:设置相等的上下 padding 值。局限性:有高度限制时不能垂直居中。代码:.box{ padding-top: 30px; padding-bottom: 30px; } 3.绝对定位居中:top:0; bottom:0;……