【问题标题】:-webkit-line-clamp Ellipsis displayed with an offset when using text-align: justify-webkit-line-clamp 使用文本对齐时显示带有偏移的省略号:对齐
【发布时间】:2017-03-06 20:25:07
【问题描述】:

我正在使用以下属性在 myClass 段落的第三行获得 省略号

p.myClass {
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
line-height: 120%;
max-height: 55px;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
font-size: 15px;
}

省略号出现了,但这是我面临的问题:

问题是我的班级也在使用:

text-align: justify;

显然省略号渲染完全忽略了 text-align: justify 属性。并且“...”出现在文本将在没有理由的情况下结束的地方

我发现了一些使用 javascript 和/或自定义 CSS 类的解决方法。但我想知道是否有任何仅使用简单 CSS 的解决方案(Webkit 是允许的,因为它只适用于 Chrome 就可以了)。

【问题讨论】:

标签: css google-chrome webkit


【解决方案1】:

基于-webkit-line-clamp的纯css方法,它隐藏原点“...”并使用自定义div:

@-webkit-keyframes ellipsis {/*for test*/
    0% { width: 622px }
    50% { width: 311px }
    100% { width: 622px }
}
.ellipsis {
    max-height: 40px;/* h*n */
    overflow: hidden;
    background: #eee;

    -webkit-animation: ellipsis ease 5s infinite;/*for test*/
    /**
    overflow: visible;
    /**/
}
.ellipsis .content {
    position: relative;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-box-pack: center;
    font-size: 20px;/* w */
    line-height: 20px;/* line-height h */
    color: transparent;
    -webkit-line-clamp: 2;/* max row number n */
    vertical-align: top;
}
.ellipsis .text {
    display: inline;
    vertical-align: top;
    font-size: 14px;
    color: #000;
}
.ellipsis .overlay {
    position: absolute;
    top: 0;
    left: 50%;
    width: 100%;
    height: 100%;
    overflow: hidden;

    /**
    overflow: visible;
    left: 0;
    background: rgba(0,0,0,.5);
    /**/
}
.ellipsis .overlay:before {
    content: "";
    display: block;
    float: left;
    width: 50%;
    height: 100%;

    /**
    background: lightgreen;
    /**/
}
.ellipsis .placeholder {
    float: left;
    width: 50%;
    height: 40px;/* h*n */

    /**
    background: lightblue;
    /**/
}
.ellipsis .more {
    position: relative;
    top: -20px;/* -h */
    left: -14px;/* -w */
    float: left;
    color: #000;
    width: 20px;/* width of the .more w */
    height: 20px;/* h */
    font-size: 14px;

    /**
    top: 0;
    left: 0;
    background: orange;
    /**/
}
<div class='ellipsis'>
    <div class='content'>
        <div class='text'>text text text text text text text text text text text text text text text text text text text text text text</div>
        <div class='overlay'>
            <div class='placeholder'></div>
            <div class='more'>...</div>
        </div>
    </div>
</div>

【讨论】:

    猜你喜欢
    • 2021-01-24
    • 2019-02-13
    • 2013-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-07
    • 1970-01-01
    • 2019-01-06
    相关资源
    最近更新 更多