【问题标题】:I can not get rid of a underline text我无法摆脱下划线文字
【发布时间】:2011-11-29 15:20:50
【问题描述】:

我得到了这个代码:

<div class="class1"><a href="http://nvm/">text</a></div>

class1的CSS代码如下:

.class1 {
       text-decoration: none;
}

输出一直显示,直到我将鼠标移到div 上。文本会被加下划线。

当然,我尝试了很多方法,例如:

.class1:hover {
      text-decoration: none;
}

我也尝试添加!important 属性,但仍然没有预期的结果。 :/

我也使用 firebug 调试过 HTML & CSS 代码,但我找不到任何属性为 text-decoration: underline; 的类。

我知道这是一个愚蠢的问题,但我没有想法。

【问题讨论】:

标签: css underline text-decorations


【解决方案1】:

对于.class1 内部的a 元素,您应该将text-decoration 属性设置为none,因为它是包含文本的元素(并且可能是您悬停在其上的元素)。

例如:

.class1 a(所有a标签的祖先是.class1

.class1 &gt; a(所有a标签,其父标签为.class1

【讨论】:

  • 谢谢。 .pagination &gt; a { text-decoration: none !important; } 工作......终于:)
【解决方案2】:

如果您在别处设置全局 &lt;a&gt; 属性,则需要专门覆盖该类的 &lt;a&gt; 标记。

.class1 a { text-decoration: none; }

.class1 a:hover {text-decoration: none; }

取决于您是否也定义了全局悬停

【讨论】:

    【解决方案3】:
    div.class1 a { Properties:values} 
    

    将是一个很好的做法。

    【讨论】:

      猜你喜欢
      • 2017-07-09
      • 2021-09-06
      • 2011-05-25
      • 2020-11-28
      • 2012-10-14
      • 1970-01-01
      • 2016-03-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多