我正在尝试使用 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/