我试图在 dom 元素上设置光标:指针,但输入不接受它。在 Chrome 中,我看到“用户代理样式表”正在覆盖我的 CSS。搞什么?
<!doctype html>
<body>
<div class='a'>
<input type='checkbox'>
</div>
<style>
.a {
cursor: pointer;
}
</style>
</body>
我看到过这个问题:Why does user agent stylesheet override my styles?但我的问题似乎不是文档类型,它是 the recommended doctype 。
使用 !important
在这里是 Not Acceptable ,我不必担心奇怪的浏览器用户代理样式。这是怎么回事?
更新:澄清一下,我的问题是为什么用户代理样式表会覆盖 CSS 以及如何让停止。我的问题不是如何解决这种行为。 css的正确行为是光标样式应该被子节点继承。
最佳答案
您需要将光标:指针添加到输入标记而不是周围的 div。
input {
cursor: inherit;
}
用户代理样式表覆盖输入,而不是其父样式表。
关于css - 为什么-光标: pointer style being overridden for input in chrome and firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24376382/