【问题标题】:Change the colour of underline on hover inside a text selection of a custom color in SCSS / CSS?在 SCSS / CSS 中自定义颜色的文本选择中更改下划线的颜色?
【发布时间】:2017-12-18 13:37:12
【问题描述】:

我在颜色 (A) 的悬停上有一个下划线。我需要将它更改为选择内的另一种颜色(在突出显示的文本内)。

问题在于下划线不会改变突出显示(选定)文本内的颜色

截图:

请问有人知道如何使它在第二个屏幕截图中显示下划线,样式为黑色?


这是从@Pawan-Kumar 的答案中借用的经过简化和编辑的代码示例(我的原始代码令人困惑):

.link{
  color:blue;
  cursor:pointer;
}

.link:hover{
color:lightblue;
  text-decoration: underline;
  text-decoration-color: red;
}

.link::selection{
  background-color:lightblue;
   
}
.link:hover::selection{
  background-color:yellow;
  text-decoration-color: black; /* This does not work*/
}
<span class='link'>This link</span> should have black underline inside highlighted text.

【问题讨论】:

  • 我认为问题可以简化如下:是否可以在一个跨度/ div 内将高亮和非高亮下划线设置为不同的颜色?

标签: css sass hover selection underline


【解决方案1】:

试试下面的css。

.link{
  color:blue;
  cursor:pointer;
}

.link:hover{
color:lightblue;
  text-decoration: underline;
  text-decoration-color: red;
}

.link::selection{
  background-color:green;
   
}
.link:hover::selection{
  background-color:yellow;
}
The color of the lines should be normal
<span class='link'>The color of the lines should be change</span>

【讨论】:

    【解决方案2】:

    我想通了:不可能……

    只有少数 CSS 属性可以应用于 ::selection 选择器:颜色、背景、光标和轮廓

    文档的链接是here

    只有 Firefox 的 has text-decoration 属性可以放入 ::selection

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-15
      • 1970-01-01
      • 2011-12-02
      • 2013-07-18
      • 1970-01-01
      • 2015-04-08
      • 2017-07-23
      相关资源
      最近更新 更多