• flex布局中text-overflow失效的解决方案


    在开发中我们经常会遇到这种布局,要求文字垂直居中,且超出使用省略号
    3fb17a7a25bc88033926ae80fe85eae3.png
    说到垂直居中,兼容性最好的就是flex布局,但在flex布局下出现了text-overflow失效的情况

    实例代码

    <div class="wrapper">
       <div class="flex item">hahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh</div>
    </div>
    .flex{
        display: flex;
        align-items: center;
    }
    .item{
        height: 40px;
        background-color: bisque;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    出现了如下效果,我们可以看出over-flow属性是生效的,而text-overflow却失效了
    b5bf47a78b8f7a50e6a92f05a882b02d.png

    解决方案

    方案一

    在文本外面再多包装一层div元素

    <div class="wrapper">
            <div class="flex item">
                <div class="item-con">hahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh</div>
            </div>
    </div>
    .flex{
        display: flex;
        align-items: center;
    }
    .item{
        height: 40px;
        background-color: bisque;
    }
    .item-con{
        overflow: hidden;
        text-overflow: ellipsis;
    }

    3fb17a7a25bc88033926ae80fe85eae3.png

  • 相关阅读:
    格式化你的git message
    git merge
    Git远程操作详解
    Limit
    EmailService
    RequestContextHolder getHttpServletRequest
    spring boot GlobalExceptionHandler @RestControllerAdvice @ExceptionHandler
    redis 的雪崩和穿透?
    FileUtil
    getWeekDay TimeUtil
  • 原文地址:https://www.cnblogs.com/ranyonsue/p/14926062.html
Copyright © 2020-2023  润新知