简体   繁体   English

CSS 选择器 a:link:hover

[英]CSS selector a:link:hover

I'm trying to create my website so you can tell where you are just by the colour of the elements in each div.我正在尝试创建我的网站,以便您可以仅通过每个 div 中元素的颜色来判断您的位置。 The website is only one page and I'm using jQuery to slide out sections of the website when you click to open that section (As opposed to having seperate .html's).该网站只有一页,当您单击打开该部分时,我使用 jQuery 滑出该网站的部分(而不是单独的 .html)。

To show them which section they have open I'm making all links in each section the same colour as the text that opens that section.为了向他们展示他们打开了哪个部分,我将每个部分中的所有链接的颜色与打开该部分的文本颜色相同。 However I also want to have <a> </a> tags which aren't links to add a bit of colour to the site and to attract viewers to key bits of information.然而,我也希望有<a> </a>标签,这些标签不是为网站添加一点色彩并吸引观众访问关键信息的链接。 For this reason I want to only apply link effects to <a> </a> tags which are actually links... So I've tried this:出于这个原因,我只想将链接效果应用于实际上是链接的<a> </a>标签......所以我试过这个:

#box1 a{
    color: #68cff2;
}

#box1 a:link:hover{
    color: #ffffff;
    background-color: #68cff2;
}

This works for the background-color as in it only changes the background colour for <a> </a> 's that have a href="..." but it doesn't change the color of the font for such links... is there any way to sort this?这适用于背景颜色,因为它只会更改<a> </a>具有 href="..." 的背景颜色,但不会更改此类链接的字体颜色。 ..有什么办法可以解决这个问题吗?

The :link pseudo-class only applies to unvisited links, as opposed to all links. :link伪类仅适用于未访问的链接,而不是所有链接。 Remember that you have visited links to account for as well.请记住,您还访问了要说明的链接。 You may need to repeat the selector for visited links, as I notice that you haven't done so:您可能需要为访问过的链接重复选择器,因为我注意到您还没有这样做:

#box1 a:link:hover, #box1 a:visited:hover {
    color: #ffffff;
    background-color: #68cff2;
}

(or just use #box1 a[href]:hover instead, more info ) (或者只是使用#box1 a[href]:hover代替, 更多信息

I should add, though, that you shouldn't be using <a> tags to mark up things that aren't links and don't serve as anchors either, just to "add a bit of colour to the site and to attract viewers to key bits of information".不过,我应该补充一点,你不应该使用<a>标签来标记那些不是链接也不作为锚点的东西,只是为了“为网站添加一点颜色并吸引观众关键信息位”。 That's not what they're designed for.那不是它们的设计目的。 A more semantic alternative would be something like <em> or <strong> , though of course you have to remove the italic or bold style if you don't want it:更语义化的替代方法是<em><strong> ,当然,如果您不想要斜体或粗体样式,则必须删除它:

#box1 a, #box1 em {
    font-style: normal;
    color: #68cff2;
}

#box1 a:hover{
    color: #ffffff;
    background-color: #68cff2;
}

Then you won't need to specify the :link and :visited pseudo-classes, since you can basically guarantee that all your remaining <a> elements are links.那么您就不需要指定:link:visited伪类,因为您基本上可以保证所有剩余的<a>元素都是链接。

Is there a need for a:link:hover{} ?是否需要a:link:hover{} Just try using a:hover {}只需尝试使用a:hover {}

a:hover也会影响锚标签,如果它们的行为方式与链接相同,最终用户可能会感到困惑。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM