简体   繁体   English

文本修饰:下划线不适用于内联块跨度元素

[英]Text-decoration: underline not applying with inline-block span elements

I'm having an issue with text-decoration: underline on two spans that use inline-block . 我遇到了text-decoration: underline的问题text-decoration: underline使用inline-block两个跨度text-decoration: underline The [problem is only one part of the URL will underline when hovered, the other does not. [问题是,只有URL的一部分会在悬停时加下划线,另一部分不会。 I need to keep the display property, otherwise text-overflow won't get applied (see: Text-overflow: ellipsis alignment issue ) 我需要保留display属性,否则不会应用text-overflow (参见: Text-overflow:省略号对齐问题

在此输入图像描述

HTML: 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: 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/ jsFiddle: http//jsfiddle.net/c7p8w/2/

By CSS specs , the underline does not affect inline blocks inside the element for which text-decoration: underline has been set. 根据CSS规范 ,下划线不会影响元素内部的内联块, text-decoration: underline已设置text-decoration: underline

You can make them underlined by explicitly setting that for them, for example by replacing the selector a:hover in your last CSS rule by the selector list a:hover, a:hover * . 你可以让他们通过更换选择明确设置,对于它们,例如强调a:hover在选择列表中你最后的CSS规则a:hover, a:hover *

This will not affect the ellipsis symbol, though. 但这不会影响省略号符号。 It is not part of any element content but inserted by a browser, so I don't think you can underline it. 它不是任何元素内容的一部分,而是由浏览器插入,所以我认为你不能强调它。

How about using border-bottom to underline the text? 如何使用border-bottom来强调文本?

a {
     text-decoration:none;
    border-bottom: 1px solid blue; /*Remove this if you want it only on hover*/
}
a:hover {
    text-decoration:none;
    border-bottom: 1px solid red;
    color:red;
}

Fiddle 小提琴

a little bit weird though... 虽然有点奇怪......

add these css? 添加这些CSS?

CSS CSS

.details h2{
    border-bottom:1px solid #fff; /*use the same color as your .details background color*/
}
.details h2:hover {
    border-bottom:1px solid #f00;
}

See DEMO on jsfiddel... http://jsfiddle.net/c7p8w/14/ 请参阅jsfiddel上的DEMO ... http://jsfiddle.net/c7p8w/14/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 <a>在对孩子进行一些定位时,</a>如何防止<a>“文本装饰:下划线”损坏<span>?</span></a> - How to keep <a> “text-decoration: underline” from breaking while applying some positioning to the child <span>? 删除文本修饰:带下划线的块内的pre标签的下划线 - Removing text-decoration:underline of pre tag inside of underlined block Elements 的样式不显示文本装饰(下划线)? - Elements's Styles does not show text-decoration (underline)? CSS 文本装饰:下划线自动应用于容器中的所有元素 - CSS text-decoration:underline auto appying to all the elements in the container 如何更换<span style="“text-decoration:" underline;”> </span>和<u></u> angular 6 中动态字符串的标记 - How to replace <span style=“text-decoration: underline;”> </span> with <u></u> tag for a dynamic string in angular 6 在悬停效果上设置文本装饰下划线 - Set text-decoration underline on hover effect 为什么文本装饰:下划线不起作用? - Why does text-decoration: underline not work? 幽灵下划线甚至文本装饰都没有 - Ghost underline even text-decoration is none IE8 不应用字体粗细:粗体和文本装饰:下划线属性 - IE8 not applying font-weight : bold and text-decoration : underline properties a:-webkit-any-link { 文字装饰:下划线; } 只能用inline-style写,为什么? - a:-webkit-any-link { text-decoration: underline; } can only be written by inline-style, why?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM