Jquery/CSS - 如何清除我无法编辑的另一个文件中设置的 CSS 背景

发布于 2024-12-03 09:17:01 字数 327 浏览 0 评论 0原文

我正在尝试覆盖按钮背景,即:

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技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

缘字诀 2024-12-10 09:17:01

背景是一个复合属性,您可以通过background-image: none仅定位图像。有关该属性的更多信息来自 MDNW3C

请注意,浏览器对此的支持可能会有所不同 - 我进行了快速的 Google 搜索,似乎 IE 和 Safari 可能对此有问题。

要在 vanilla JS 中定位此属性,您可以使用驼峰式大小写:

element.style.backgroundImage = 'none';

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:

element.style.backgroundImage = 'none';
万人眼中万个我 2024-12-10 09:17:01

如果 !important 不起作用(请参阅 Pbirkoff 的答案),那么您可以直接查看原始 css 或使用某种类型的检查工具(例如 firebug)。从那里开始,这是一个 css 选择层次结构的问题(参见 http://www.w3 .org/TR/CSS21/cascade.html#cascade)。您需要做的是创建一个优先于原始规则的新规则,或者重新创建确切的规则并删除图像。例如...

...在original.css中:

.something {
  background: url("path/to/image.jpg") no-repeat scroll left center transparent;
}

...在your.css中:

.something {
  background-image: none;
}

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:

.something {
  background: url("path/to/image.jpg") no-repeat scroll left center transparent;
}

...in your.css:

.something {
  background-image: none;
}
橘虞初梦 2024-12-10 09:17:01

在值后面加上 !important 有用吗?例如:

background: none!important;

Does putting !important after the value work? e.g:

background: none!important;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文