You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Firefox中:hover与:visited伪类样式冲突问题求助——已访问元素hover状态异常

Fixing :visited and :hover Style Conflict in Firefox

I've run into this exact issue with Firefox before—turns out it handles the order of pseudo-class rules a bit differently than Chrome, which causes that weird intermediate blue flash when hovering a visited link. Let's break down the problem and fix it.

The Root Cause

Your original CSS has the .button:visited:hover rule placed before .button:hover. Since both selectors have the same specificity (class selector + single pseudo-class), Firefox applies the later rule first when hovering a visited element—so it briefly shows the blue from .button:hover before the red from .button:visited:hover kicks in. Chrome handles this order more intuitively, but Firefox sticks strictly to the "last rule wins" principle here.

The Fix

Adjust the order of your CSS rules to place .button:visited:hover after .button:hover. This ensures the visited hover style takes precedence when applicable. Here's the corrected code:

.button { 
  background-color: black; 
  padding: 10px; 
  text-decoration: none; 
  transition: background-color 0.5s ease; 
}
.button:hover { 
  background-color: blue; 
}
.button:visited { 
  background-color: green; 
}
.button:visited:hover { 
  background-color: red; 
}

Why This Works

  • For unvisited buttons: The default black background switches to blue on hover, exactly as you want.
  • For visited buttons: The default green background will directly switch to red on hover, no intermediate blue—since .button:visited:hover comes after .button:hover, its style overrides the generic hover rule for visited links.

Just a quick note: Browsers have privacy restrictions on :visited (to prevent scripts from detecting if a user has visited a link), but background-color is one of the allowed properties, so this fix is safe and compliant.

内容的提问来源于stack exchange,提问作者Anonymous

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 10:22:39