Search code examples
cssgoogle-chromegoogle-chrome-extension

How to reset all styles of a div and decedents back to Chrome defaults


I'm not sure this is possible, but id like to set all user styles back to chrome defaults for div and descendants.

I'm building a Chrome plugin that creates a popup on any web page, however due to the fact every page has a plethora of custom styles, trying to track down every inconsistency and overwrite it with my divs (and descendants) custom style, it is becoming a nightmare.

Every time I think I've covered all bases another site implements something else that needs to be overridden.

What would be the easiest approach to standardize my popup in this situation?

One approach I can think of is to (bite the bullet) and get a hold of the the default Chrome CSS styles and implement them into a series of catch all descendant selectors, however surely there is a better way.


Solution

  • If you want to be absolutely sure that the styling of your elements is not affected by the web-page's CSS, there are 2 possible solutions:

    1. Use an iframe to implement your popup. (This solution is "safe" and simple enough, but based on the kind of interaction between the popup and the web-page it might become cumbersome.)

    2. Utilize the Shadow DOM. (This is probably the "proper" solution, but the implementation might be a little more complicated.)

    Some resources regarding the 2nd solution: