Jquery/CSS - 如何清除我无法编辑的另一个文件中设置的 CSS 背景
我正在尝试覆盖按钮背景,即:
background: url("path/to/image.jpg") no-repeat scroll left center transparent;
我想删除图像,但由于我无法访问该文件,我需要通过 CSS 或 Jquery 覆盖。
知道如何做到这一点,因为像 background: none
这样简单的东西不起作用,我无法使用 Jquery 删除整个类,而且我不想放入透明的 1x1px png 和浪费 HTTP 请求。图片必须删除...知道我能做什么吗?
感谢您的帮助。
I'm trying to overwrite a button background, which is:
background: url("path/to/image.jpg") no-repeat scroll left center transparent;
I want to get rid of the image, but as I cannot access the file, I need to overwrite via CSS or Jquery.
Any idea how I can do this, since something easy like background: none
doesn't work, I cannot use Jquery to remove the whole class and I don't want to put in a transparent 1x1px png and waste an HTTP request. The image has to go... any idea what I can do?
Thanks for help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
背景是一个复合属性,您可以通过
background-image: none
仅定位图像。有关该属性的更多信息来自 MDN 和 W3C。请注意,浏览器对此的支持可能会有所不同 - 我进行了快速的 Google 搜索,似乎 IE 和 Safari 可能对此有问题。
要在 vanilla JS 中定位此属性,您可以使用驼峰式大小写:
Background is a compound property, you can target just the image by
background-image: none
. More info on the property from MDN and W3C.Be advised that browser support for this may vary - I've done a quick Google search and it seems that IE and Safari may have issues with this.
To target this property in vanilla JS, you'd use camel case:
如果
!important
不起作用(请参阅 Pbirkoff 的答案),那么您可以直接查看原始 css 或使用某种类型的检查工具(例如 firebug)。从那里开始,这是一个 css 选择层次结构的问题(参见 http://www.w3 .org/TR/CSS21/cascade.html#cascade)。您需要做的是创建一个优先于原始规则的新规则,或者重新创建确切的规则并删除图像。例如......在
original.css
中:...在
your.css
中:If
!important
doesn't do the trick (see Pbirkoff's answer) then you can look directly at the original css or use some type of inspection tool (e.g. firebug). From there it's a matter of the css selection heirarchy (see http://www.w3.org/TR/CSS21/cascade.html#cascade). What you'll want to do is either create a new rule that takes precedence over the original or recreate the exact rule and just knock out the image. For example......in
original.css
:...in
your.css
:在值后面加上 !important 有用吗?例如:
Does putting !important after the value work? e.g: