我试图将光标:指针设置在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?但我的问题似乎不是doctype,即the recommended doctype。
在这里使用!important
是不可接受的,我不必担心奇怪的浏览器使用方式。发生了什么事?
更新:为了澄清,我的问题是关于用户代理样式表覆盖css以及如何使 停止的原因。我的问题是不我怎么能解决这个问题。 css的正确行为是游标样式应该由子节点继承。
答案 0 :(得分:3)
您需要将cursor:指针添加到输入标记而不是周围的div。
input {
cursor: inherit;
}
用户代理样式表覆盖输入,而不是其父级。
答案 1 :(得分:1)
试试这个:
<!doctype html>
<body>
<div>
<input class="a" type='checkbox'>
</div>
<style>
.a {
cursor: pointer;
}
</style>
</body>