Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add CSS to pages through a CSS file

I was wondering if it was possible to add CSS to pages through a CSS file, similarly to adding JS to pages through a JS file (contentscript). So, I could just define what pages said CSS file would work on and then it would take effect just like a contentscript. I understand that it is possible to add CSS through a JavaScript file, but it would be more convenient to do it this way instead if possible. If it's not possible, then of course I must use contentscript, but I would first like to know before I rule out any possibilities. I've searched and received no answers - either I'm searching wrong or it really isn't possible. Chrome extensions have come a long way, though, so I'm still not ruling it out until someone who knows can tell me yes & how or no. Thanks for any responses.

like image 741
Anonymous Avatar asked Mar 27 '11 22:03

Anonymous


People also ask

How do you add CSS to pages?

CSS can be added to HTML documents in 3 ways: Inline - by using the style attribute inside HTML elements. Internal - by using a <style> element in the <head> section. External - by using a <link> element to link to an external CSS file.


1 Answers

Your manifest file must contain a content script pointing to a CSS file, that will load when a url matches your selected url fields...

"content_scripts": [ {    "css": [ "scrollbars.css" ],    "matches": [ "http://www.google.com/*" ] } ], 

This is the same method you would use to inject javascript code, except you would point to a js file instead...

More information here...

like image 193
David Avatar answered Sep 22 '22 04:09

David