使用 css 断字或其他东西将带有 html 标签的文本子串起来?

Res*_*hma 1 javascript css

var txt = 'Some texts, html tags & all values i can enter through text box';
txt= txt.substring(0,255)+'...';
Run Code Online (Sandbox Code Playgroud)

我可以使用 css 做这件事吗?

我的问题是,如果txt包含 HTML 标签,则在执行子字符串后,结束标签会丢失并且会中断。

Ish*_*ain 5

但为此你应该设置width元素 -

试试这个 CSS -

 overflow: hidden;
 text-overflow: ellipsis;
 white-space: nowrap;
 width: 100%;
 display: inline-block;
Run Code Online (Sandbox Code Playgroud)

在jsfiddle中看到