相关疑难解决方法(0)

如何使CSS文本修饰覆盖工作?

有些日子我发誓我会发疯.这是其中一天.我认为我的CSS在这里相当简单,但它似乎并没有起作用.我错过了什么?

我的CSS看起来像这样:

ul > li {
    text-decoration: none;
}
ul > li.u {
    text-decoration: underline;
}
ul > li > ul > li {
    text-decoration: none;
}
ul > li > ul > li.u {
    text-decoration: underline;
}
Run Code Online (Sandbox Code Playgroud)

我的HTML看起来像这样:

<ul>
  <li>Should not be underlined</li>
  <li class="u">Should be underlined
    <ul>
      <li>Should not be underlined</li>
      <li class="u">Should be underlined</li>
    </ul>
  </li>
</ul>
Run Code Online (Sandbox Code Playgroud)

然而它出现了这样的:

图片

html css text-decorations

31
推荐指数
2
解决办法
2万
查看次数

无法撤消子元素的文本修饰

说你有这个HTML:

<a href="#">
    This is underlined
    <span>
        This isn't.
    </span>
</a>
Run Code Online (Sandbox Code Playgroud)

这个css:

a:hover {
    text-decoration: underline; /* I know, this is enabled by default. */
}

a:hover span {
    text-decoration: none !important;
}
Run Code Online (Sandbox Code Playgroud)

为什么a> span元素仍然有下划线.我很确定你应该通过使用'none'来取消装饰.我知道你可以用这个来达到我想要的结果:

<a href="#">
    <span class="underlined">
        This is underlined
    </span>
    <span>
        This isn't.
    </span>
</a>
Run Code Online (Sandbox Code Playgroud)

再加上这个css:

a:hover {
    text-decoration: none;
}

a:hover span.underlined {
    text-decoration: underline;
}
Run Code Online (Sandbox Code Playgroud)

但是......这对我来说没有意义,为什么你不能取消子元素的文本修饰.所以为什么...?

编辑:内联块

根据@amosrivera,当你使用内联块时,它确实有效.我可以确认这适用于Safari和Chrome!

a:hover span{
    text-decoration:none;
    display:inline-block;
}
Run Code Online (Sandbox Code Playgroud)

如上所述,这适用于Safari和Chrome,但不适用于Firefox.以下解决方案适用于Firefox,但不适用于Safari和Chrome ...

a:hover span{
    text-decoration:none;
    display:block;
}
Run Code Online (Sandbox Code Playgroud)

小桌子:

    CSS-Rule            |    Webkit    | …
Run Code Online (Sandbox Code Playgroud)

html css

29
推荐指数
2
解决办法
7709
查看次数

用不同颜色标注html锚点

是否可以使用除文本颜色之外的颜色为锚标记加下划线?任何例子将不胜感激.

编辑: 是否可以将颜色指定为十六进制,例如#8f867c?

html css anchor

8
推荐指数
2
解决办法
3万
查看次数

任何阻止CSS的方法:将孩子的悬停文字装饰下划线?

可能重复:
如何使CSS文本修饰问题起作用?

我正在使用jquery切换效果来显示或隐藏有关列表元素的更多信息:

jQuery(document).ready(function($) {
    $("ul p").hide();
    $("ul li").addClass("link");
    $("ul li").click(function () {
    $("p", this).toggle(300);
    });
});
Run Code Online (Sandbox Code Playgroud)

这适用于以下结构:

<ul>
<li>List element 1<p>Additional info 1</p></li>
<li>List element 2<p>Additional info 2</p></li>
</ul>
Run Code Online (Sandbox Code Playgroud)

为了使它看起来"可点击"我是造型.link与css:

ul li.link {
    color: #0066AA;
}

ul li.link:hover {
    text-decoration: underline;
    cursor: pointer;
}
Run Code Online (Sandbox Code Playgroud)

但我不希望显示的文本看起来像一个链接所以:

ul li.link p{
    color: black;
    text-decoration: none;
}

ul li.link p:hover {
    cursor: text;
    text-decoration: none;
}
Run Code Online (Sandbox Code Playgroud)

但是<p>在悬停时仍有下划线(蓝色),尽管投掷文字装饰:无; 在每个自由空间!根据我的理解,这是因为子样式应用于父级之上,所以我实际上正在尝试将"无"放在下划线之上并让它消失.

所以我的问题(最终!)是这样的:有什么办法来摆脱下划线没有采取<p>出来的<li>(我不希望因其他原因做)?

css parent-child hover text-decorations

5
推荐指数
1
解决办法
7479
查看次数

标签 统计

css ×4

html ×3

text-decorations ×2

anchor ×1

hover ×1

parent-child ×1