javascript - html限制跨度中的字母

标签 javascript html css

我正在尝试使用 CSS 限制标签可以显示的字母数量,就像 YouTube 上的标题一样。我在看样式,看不出他们是怎么做到的,或者他们是否使用了 JS。谢谢

最佳答案

您可以像这样 chop 文本并添加省略号:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>

p {
    width: 300px;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

</style>
</head>
<body>

<p>This is some text this is some text this is some text this is some text</p>

</body>
</html>

关于javascript - html限制跨度中的字母,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23146213/

相关文章:

html - Twitter Bootstrap 选择标签问题

javascript - 打印时更改元素的颜色

css - 仅使用 CSS 的 Bootstrap 自定义轮播

javascript - Opentok连续窗口重载

javascript - TypeError : repos. 映射不是函数

javascript - 合并多个javascript文件

Javascript - 复选框的 Onchange 事件仅适用于 Firefox 和 Opera?

基于另一个 div 样式的 JavaScript 样式 div [帮助]

javascript - JavaScript 中的所有函数本质上都是方法吗?

html - 无法对齐 bootstrap html 代码中的 div