html - How to show horizontal ellipsis at bottom of the text
问题描述
I'm using a HTML Entity to show three dots (...) to indicate uses that there was having more text. There were other ways to show this through CSS (text-overflow: ellipsis;
), but I have some limitations to use CSS style.
The issue is, the ellipsis is showing in the middle of the text - I need it the same as how manual three dots appear after a text like,
Many people have sent language examples over the years...
My current output:
horizontal ellipsis
<p><span>Sample Text:</span>Many people have sent language examples over the years, but we want more! We'd love to add more examples…</p>
解决方案
ToolJS是一个实用的 JavaScript 库,其功能可以解决此类问题并简化您的工作流程。
它包含一个操作字符串的“Str”模块,其中包括.truncate函数,它可以满足您的需求。
如何使用它
var Str = ToolJS.export("Str");
var myString = "Many people have sent language examples over the years, but we want more! We'd love to add more examples";
var newString = Str.truncate(myString, {
limit: 40, // this is the number of characters you want to show in your string
replacement: "..." // this is the replacement string
});
// Or you could do a shorthand implentation using the same method
var newString = Str.truncate(myString, 40, "...");
// To show it on your DOM
var DOM = ToolJS.export("DOM");
DOM.html("p", `<p><span>Sample Text:</span>${newString}</p>`);
<script src="https://unpkg.com/@redeakaa/tooljs@1.0.1/dist/umd/tooljs.min.js"></script>
<p><span>Sample Text:</span>Many people have sent language examples over the years, but we want more! We'd love to add more examples</p>
推荐阅读
- r - pdf_text 函数不释放内存(在 Windows 上)
- ibm-cloud - IBM Watson Assistant:尝试评估和比较多个上下文变量
- android - 是否可以在 Android TextView 或 Webview 中设置 div 类的样式?
- android - 结合使用 ScrollView Activity 和 adjustPan 时的空白
- c# - 如何将@RenderBody() 分成两部分
- common-lisp - Common Lisp 在宏中生成变量名
- reactjs - 如何测试使用反应上下文 API 的组件?
- javascript - 获取所有标题并递归创建树
- javascript - 使用 JavaScript,是否可以从传出的获取请求中捕获正文有效负载?
- node.js - Express 服务于 2 个不同的 Angular PWA