开发者社区 问答 正文

一行文字时垂直居中 用css

如何让它一行文字的时候垂直居中

    <style type="text/css">
        .ellipsis-2 {
            display: -webkit-box;
            overflow: hidden;
            text-overflow: ellipsis;
            word-wrap: break-word;
            white-space: normal !important;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
            color: #fff;
        }
    </style>
    <div style="padding: 0 10px;height: 50px;background-color: #7092BE;width: 200px;">
        <p class="ellipsis-2">
            一行文字时垂直居中,两行文字时换行
        </p>
    </div>

展开
收起
杨冬芳 2016-06-12 17:52:01 2295 分享 版权
1 条回答
写回答
取消 提交回答
  • IT从业

    在div上面使用flex

        height: 200px;
        width: 200px;
        background-color: red;
        display: flex;
        justify-content: space-around;
        flex-direction: column;
        align-items: center;
        word-break: break-all;
    2019-07-17 19:34:49
    赞同 展开评论
问答分类:
问答地址: