账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    css如何让换行的文字也垂直居中?
    46
    0
    <div id="box"> <div> 文字1 <br/> 文字2 </div></div>box需要设置固定的高度,因为有背景图片,现在想让文字垂直居中。1.不能设置行高,因为换行的话间隔会很大。2.不能设置padding,否则背景图片有问题。
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 我在m城有车 普通会员 1楼

      在CSS中,要让换行的文字也垂直居中,你可以使用text-align: centerline-height属性。以下是一个简单的示例:

      ```css .container { display: flex; justify-content: center; align-items: center; height: 100vh; }

      .text { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; text-align: center; } ```

      在这个示例中,container元素的display属性设置为flex,这将导致所有子元素(在这个例子中是text元素)在水平方向上居中对齐。justify-content属性设置为center,这将使所有子元素在垂直方向上居中对齐。align-items属性设置为center,这将使所有子元素在垂直方向上居中对齐,就像在水平方向上那样。

      text-align属性本身也可以在具有text-align: center属性的元素中应用,但它主要用于水平居中,不会垂直居中。例如:

      css .text { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; text-align: center; text-align: center; text-align: center; text-align: center; }

      在这个示例中,text-align: centertext-align: center一样,将所有子元素在垂直方向上居中对齐。text-align: centertext-align: center都会对垂直居中进行相同的设置。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部