2017-08-08 45 views
0

我确定这非常简单,但我无法弄清楚如何操作,也没有找到相关帮助。如何在链接中选择强标记并在悬停时更改颜色

我有一个链接。链接中的一些文本位于<strong>标记内。 <strong>文字有一种颜色。在悬停时,<strong>文字不会改变颜色。我如何让它改变颜色?

a:link { 
    color: rgb(25, 50, 50); 
    text-decoration: none; 
} 

a:visited { 
    color: rgb(25, 50, 50); 
    text-decoration: none; 
} 

a:hover { 
    color: rgb(100, 200, 200); 
    text-decoration: none; 
} 

a:active { 
    color: rgb(100, 200, 200); 
    text-decoration: none; 
} 

strong { 
    color: rgb(50, 100, 100); 
} 
<li><a href="xyz.html"><img src="resources/logo.jpg"><div class="list_text"><strong>Heading</strong><br>Sub heading</div></a></li> 

我想strong标签内的文本上悬停,并积极为彩色为“副标题”文本RGB(100200200)相同。

+0

您希望强标记中的文本在链接的任何部分悬停时发生更改,还是仅当强标记中的文本悬停时才更改? – j08691

+0

我希望所有文本(强标签内部和外部)在悬停时更改颜色。 – Markeee

回答

3

试试这个:

a:link { color:rgb(25,50,50); text-decoration:none; } 
 
a:visited { color:rgb(25,50,50); text-decoration:none; } 
 
a:hover strong { color:rgb(100,200,200); text-decoration:none; } 
 
a:hover { color:rgb(100,200,200); text-decoration:none; } 
 
a:active { color:rgb(100,200,200); text-decoration:none; } 
 

 
strong { color:rgb(50,100,100); }
<a href="xyz.html"><strong>Heading</strong><br>Sub heading</a>

+0

谢谢。但它仍然不适合我。我将编辑我的问题,因为代码比我上面给出的简化版本稍微复杂一点。 – Markeee

+0

对不起,我犯了一个简单的错误。您的解决方案完美运作谢谢 – Markeee

2
a:hover { 
    color: rgb(100, 200, 200); 
} 

a:hover strong { 
    color: rgb(100, 200, 200); 
} 

a:hover, 
a:hover strong { 
    color: rgb(100, 200, 200); 
} 

的jsfiddle演示:https://jsfiddle.net/b0nrf70p/1/

1

您可以修改现有的悬停选择,包括与a:hover, a:hover > strong

强元素

a:link { 
 
    color: rgb(25, 50, 50); 
 
    text-decoration: none; 
 
} 
 

 
a:visited { 
 
    color: rgb(25, 50, 50); 
 
    text-decoration: none; 
 
} 
 

 
a:hover, a:hover > strong { 
 
    color: rgb(100, 200, 200); 
 
    text-decoration: none; 
 
} 
 

 
a:active { 
 
    color: rgb(100, 200, 200); 
 
    text-decoration: none; 
 
} 
 

 
strong { 
 
    color: rgb(50, 100, 100); 
 
}
<a href="xyz.html"><strong>Heading</strong><br>Sub heading</a>

0

Strong element有上下文的含义,因此它具有默认风格“浏览器用户代理样式表”的顺序重要。

解决方案是使用Cascading Style Sheets (CSS)级联设计来定义元素和重写样式。我使用级联路径“一个强大的”和值“inherit”从父元素中获取值。

这里是preview和代码:

a { 
 
    text-decoration: none; 
 
    cursor: pointer; 
 
} 
 
a strong { 
 
    color: inherit; 
 
    font-weight: inherit; 
 
} 
 

 
a:link, 
 
a:visited { 
 
    color: rgb(25, 50, 50); 
 
} 
 

 
a:hover, 
 
a:active { 
 
    color: rgb(100, 200, 200); 
 
} 
 

 
strong { 
 
    color: rgb(50, 100, 100); 
 
}
<a>anchor <strong>strong</strong></a>

我希望它能帮助。

相关问题