单行文字与多行文字在div排列中垂直居中

在一行四列、固定高度的div中,有的div里p为单行,有的p为多行,要使他们都能保持在div中居中。

  1. 为父元素设置高度、行高
  2. 为p元素设置display、行高、位置
div{
    width:100px;
    height:200px;
    line-height:200px;
}
div p{
    display:inline-block;
    vertical-align:middle;
    font-size:20px;
    line-height:25px;
}
    
    

猜你喜欢

转载自blog.csdn.net/weixin_40431771/article/details/82801455