21

Is it possible to add css rule to an element at some page by adblock? Something like this

#myElement {
    color: white !important;
}

I tried to find a script that updates style of this element on page load but it seems that it is not a best way.

4 Answers 4

39

It's possible to do it on uBlock Origin and Adguard (as far as I know). Each has its own syntax for the styling rules, but uBlock is capable understanding both.


Here is an example of a CSS rule that changes Twitter background:

twitter.com#$#body.logged-in{ background-color: #8c8787 !important; }

The styling filters should be constructed like this:

<domain> + #$# + <selector> + { <style> }

Just avoid puting a space between the selector and the opening brace. Cause it can give you some trouble. Reference:

https://github.com/gorhill/uBlock/wiki/Static-filter-syntax#style https://adguard.com/en/filterrules.html#cosmetic-css-rules

0
17

The other answers weren't working for me but there is a way to change an element's style:

example.com##h1:style(background-color: blue !important)

Make sure not to use curly brackets.

There is also some documentation on GitHub.

EDIT: As BeeLabeille mentioned this advice seems specific to uBlock.

2
  • 2
    It's probably worth mentioning that, similar to the other answers, your solution also applies to ublock and not adblock as specified in the question Jan 3, 2020 at 20:59
  • Can confirm, this is the only solution that worked for adblock (Sept 2022)
    – def_init_
    Sep 4, 2022 at 22:23
0

I don't think it's possible for AdBlock to change CSS properties, you can use an extension like Stylish (available for Firefox and Chrome) to do just that though.

0

For AdBlock Plus, you can try this:

##.ytp-pause-overlay, .ytp-scroll-min
##.html5-endscreen, .ytp-player-content, .videowall-endscreen, .ytp-endscreen-paginate, .ytp-show-tiles
##.ytp-endscreen-content

This should disable the display of ads during the pause, and recommended videos, at the end of the video.

PS: Ah.. this is not the subject of the question.. this removes the class from the div element. Well, maybe someone will come in handy, to delete unnecessary blocks in the Youtube player.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.