【发布时间】:2020-03-09 01:49:27
【问题描述】:
编辑:如所指出的,将 省略号 更改为 省略号。共同的共识是我需要使用 js 来做同样的事情。谢谢你。
原始问题: 我正在尝试显示一张仅显示一行描述的卡片,并用省略号终止该行。点击后,应该可以看到完整的描述。通过指定
,我只能显示 1 行overflow:hidden;
whitespace:nowrap;
text-overflow:ellipsis;
但它切断了最后一个词。有没有办法只显示一行而不断字?
这是我的 codepen 的链接:https://codepen.io/npnair/pen/BaNmXyM?editors=1100
这里是html:
<div class="search-card">
<img class="search-card-img-left"
src="https://image.shutterstock.com/image-photo/spring-blossom-background-beautiful-nature-260nw-1033292395.jpg">
<div class="search-card-body">
<h2 class="search-card-title"> Trump tells Bar he can stay - but makes clear that the tweets will continue </h2>
<p class="search-desc"> President has full faith and confidence in his hand-picked AG- and something else to test the overflow property of the description.and something else to test the overflow property of the description. and something else to test the overflow property of the description.</p>
</div>
</div>
这是css:
.search-card {
width: 800px;
background-color: lightgray;
border: 1px solid #888888;
border-radius: 0.25rem;
height: 120px;
}
.search-card-img-left {
padding:20px;
height:80px;
width: 80px;
border:1px solid;
float:left;
}
.search-card-title {
margin: 0.25rem;
border: 1px solid;
text-align:left;
}
.search-card-body {
text-align:left;
display:inline;
}
.search-desc{
text-overflow: ellipsis;
overflow-wrap: break-word;
display:inline;
word-break: keep-all;
}
【问题讨论】:
-
这能回答你的问题吗? Limit text length to n lines using CSS
-
它切断了最后一个词......
-
安静晚了,我不知道你是否解决了你的问题以及如何,现在可以使用线夹,只有IE(不是Edge)基本不支持它:见caniuse.com/?search=line-clamp。如果您仍然关心这个问题,请在我的答案中添加一个 sn-p ;)
标签: javascript html css frontend