html - CSS 列表悬停在 Google Chrome 中不起作用

标签 html css list google-chrome

我有一个 HTML 列表,当将鼠标悬停在每个列表项上时,文本和元素符号点将改变颜色。

HTML

<ul>
   <li>A bullet point</li>
   <li>Another bullet point</li>
   <li id="thirdpoint"><button onclick="document.getElementById('thirdpoint').innerHTML='Third bullet point';">Add bullet point</button></li>
</ul>

CSS

ul li:hover {
   color:red;
}

JSFiddle

输出应如下所示,可在 Microsoft Edge、Internet Explorer、Firefox 和 Safari 中正常运行。

Working list hover

然而,Google Chrome 似乎无法正确渲染悬停。其一,元素符号点的颜色没有改变。

Google Chrome list hover

当单击“添加元素符号点”按钮时,元素符号点有时会改变颜色,但当它发生时,即使将光标移出,它也会保持这种状态。调整窗口大小似乎可以解决这个问题。

Stuck bullet hover

那么我如何才能使 HTML/CSS 在 Google Chrome 中正常工作呢?我的直觉是,由于卡住的元素符号点颜色可以自行纠正,这可能是浏览器错误。如果是这样,有什么解决方法吗?如果没有,我该如何修复代码?

最佳答案

这是一个你可以使用的技巧

ul li:hover {
  color:red;
}
li:before {
  content: "• ";
}
ul {
  list-style: none;
}
<ul>
    <li>A bullet point</li>
    <li>Another bullet point</li>
    <li id="thirdpoint"><button onclick="document.getElementById('thirdpoint').innerHTML='Third bullet point';">Add bullet point</button></li>
</ul>

关于html - CSS 列表悬停在 Google Chrome 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35234233/

相关文章:

Javascript 悬停事件

list - 如何从列表中获取除与某些字符串相关的数字之外的所有数值

c# - 将字符串列表转换为字节数组

html - CSS 等距立方体上的面动画

c++ - 错误 : assignment to '_List_iterator<unsigned int,unsigned int &,unsigned int *>' from 'int'

html - 使用 Bootstrap 响应式网格系统时如何为图像提供动态宽度和高度

html - 在 Bootstrap 3 中用鼠标选择(突出显示)的文本样式

javascript - 如何使用数值数组作为表单输入名称?

html - IE8 忽略 CSS 样式

CSS 模块和 CSS 关键帧动画