gpt4 book ai didi

css - -webkit-line-clamp 省略号在使用text-align : justify时显示偏移量

转载 作者:行者123 更新时间:2023-11-28 12:09:58 25 4
gpt4 key购买 nike

我正在使用以下属性在 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;
}

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

问题是我的类(class)也在使用:

text-align: justify;

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

我发现了一些使用 javascript 和/或自定义 CSS 类的解决方法。但我想知道是否有任何仅使用简单 CSS 的解决方案(Webkit 是允许的,因为如果它只在 Chrome 上工作就没问题)。

最佳答案

基于-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>

关于css - -webkit-line-clamp 省略号在使用text-align : justify时显示偏移量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33146598/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com