【发布时间】:2019-10-24 12:31:14
【问题描述】:
如果文本溢出,哪些 CSS 属性用于在文本末尾打印 3 个点?
【问题讨论】:
-
使用文本溢出:省略号;属性
-
嗨 Anand,欢迎来到堆栈溢出!stackoverflow.com/a/1101702/656840
如果文本溢出,哪些 CSS 属性用于在文本末尾打印 3 个点?
【问题讨论】:
.para{
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
<div style="max-width: 400px; margin: 0 auto;"><P class="para">Lorem ipsum dolor sit amet, quas malorum qui an. Ius reque fugit labore te. Te eam decore comprehensam, te brute petentium per. Usu melius antiopam scripserit in.</p></div>
【讨论】:
您应该使用 text-overflow CSS 属性设置隐藏的溢出内容如何向用户发出信号。它可以被剪裁、显示省略号 ('...') 或显示自定义字符串。图片你有一个长句子=>“我正在为你写一个长句子” 现在以下每一项都会改变结果
text-overflow: clip; // I'm writing a long sentence for
text-overflow: ellipsis; // I'm writing a long sentence for ...
text-overflow: "-"; // I'm writing a long sentence for -
text-overflow: ""; // I'm writing a long sentence for
请注意,text-overflow 属性不会强制发生溢出。要使文本溢出其容器,您必须设置其他 CSS 属性:溢出和空白。例如:
overflow: hidden;
white-space: nowrap;
.text-overflow {
/* custom style */
width: 10em;
outline: 1px solid #000;
margin: 0 0 2em 0;
/* by text-overflow you can trim your text */
text-overflow: ellipsis;
/**
* Required properties to achieve text-overflow
*/
white-space: nowrap;
overflow: hidden;
}
<p class="text-overflow">This is an example text showing nothing interesting but the truncated content via text-overflow shorthand property.</p>
还有check this link 它为您提供了完整的示例代码
【讨论】: