【发布时间】:2013-05-25 12:18:00
【问题描述】:
我在使用inline-block 的两个跨度上遇到了text-decoration: underline 的问题。 [问题只是悬停时URL的一部分会加下划线,其他部分不会。我需要保留 display 属性,否则text-overflow 不会被应用(参见:Text-overflow: ellipsis alignment issue)
HTML:
<div class="details" itemscope itemtype="http://data-vocabulary.org/Product">
<h2>
<a class="heading" href="/product/acmesw" title="Acme Super Widget">
<span class="trunc" itemprop="name">Acme Super Widget 3000</span>
<span itemprop="offerDetails" itemscope itemtype="http://data-vocabulary.org/Offer">- <meta itemprop="currency" content="AUD" /><spanitemprop="price">$199.95</span></span>
</a>
</h2>
</div>
CSS:
.details {
width:300px;
border:1px solid red;
}
.trunc {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
max-width:60%;
}
h2 span {
display:inline-block;
vertical-align:top;
}
a:hover{
text-decoration:underline;
color:red;
}
jsFiddle:http://jsfiddle.net/c7p8w/2/
【问题讨论】:
-
问题的核心是您的
.trunc没有继承text-decoration: underline来自其父<a>。您可以简单地添加.trunc { ..; text-decoration: inherit; .. }。我不知道你是否会对结果感到满意,因为省略号仍然没有下划线......我不知道如何实现。 -
Re:省略号下划线问题 - 一直是 asked before,看来唯一的解决方案是使用
border-bottom而不是text-decoration: underline。对不起。
标签: html css text-decorations