【发布时间】:2014-07-25 14:57:15
【问题描述】:
我想在标题旁边有一个摘要,如果摘要太长,我希望它被截断为像这样的经典省略号:
我的标题这是一个很长的文本,我想...
我不想定义摘要的宽度,我希望它占据同一行的所有房间。我尝试使用overflow: hidden 和text-overflow: ellipsis,但我不能将截断的文本放在标题旁边。如果文本在标题旁边,则不截断摘要;如果文本被截断,则它不在标题旁边。
这些是我的一些尝试:
<h2 class="title">
My Title
<span class="tiny shortening">This is a very long text that I want to shorten This is a very long text that I want to shorten This is a very long text that I want to shorten This is a very long text that I want to shorten shorten</span>
</h2>
<h2>
My Title
<div class="tiny shortening">This is a very long text that I want to shorten This is a very long text that I want to shorten This is a very long text that I want to shorten This is a very long text that I want to shorten </div>
</h2>
用css
.title {
white-space: nowrap;
}
.inline {
display: inline;
}
.tiny {
font-size: 70%;
}
.shortening {
white-space: nowrap;
overflow: hidden !important;
text-overflow: ellipsis;
}
【问题讨论】:
-
尝试将 .shortening 上的样式改为 .title。