!important只能加在属性上吗,不能给div或者img加上important?

.enlarge_div img:hover {
    transition: 1s;
    transform: scale(1.2) !important;
}
阅读 3.3k
3 个回答

不能直接在选择器上加 !important, 不过有一个替代方案:.div -> .div.div,双类名可以达到 !important 的效果。

.enlarge_div.enlarge_div img:hover {
    transition: 1s;
    transform: scale(1.2);
}

这属性本来就不该滥用 嫌效率低为什么不用css权重来控制呢

一般正确设置好css 的优先级,是不需要用important 的。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题