Firefox 和 Edge 没有这个问题
因此,对于 Chrome,当我尝试选择文本时,文本确实被选中但不可见,我的意思是文本背景不会改变。其他网站好像没问题。只有 GitHub 网站是这样的。
我认为这是 GitHub 网站的一个错误,因为阻止更改文本背景的 CSS 样式来自 GitHub 服务器。
临时解决方案是在开发工具控制台窗口中运行这段代码:
const addStyle = (styleString) => {
const style = document.createElement('style');
document.head.append(style);
style.textContent = styleString;
};
addStyle(`
body *::selection {
background-color: rgb(50 80 90 / 0.5) !important;
}
`);
是的,每次刷新页面,我们都得重新运行这段代码。这只是一个快速的临时解决方案。