文字在div中文字垂直居中有两种情况:单行文字、多行文字
一、单行文字
只需设置div的高度与文字的行高一样就OK了,即 line-height 和height 的数值一样。
例如:div{ height: 20px; line-height: 20px; }
二、多行文字
只要设定 padding-bottom 和 padding-top 一样的就OK了。
例如:div{ padding-top: 20px; padding-bottom: 20px; }
一、单行文字
只需设置div的高度与文字的行高一样就OK了,即 line-height 和height 的数值一样。
例如:div{ height: 20px; line-height: 20px; }
二、多行文字
只要设定 padding-bottom 和 padding-top 一样的就OK了。
例如:div{ padding-top: 20px; padding-bottom: 20px; }
本文详细介绍了如何在div元素中实现单行和多行文字的垂直居中,包括设置高度、行高、填充等技巧,并提供了实例演示。
2660

被折叠的 条评论
为什么被折叠?



