Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to have a CSS selector apply to a specific host? (For my custom browser stylesheet.)

Tags:

css

webkit

I want to apply styles (edit:in my browser's user-defined stylesheet, a local file on my machine that let's me customize how other people's websites render for me) to a specific site, but the selectors on many web pages are often generic (and obviously out of my control, since they're not my websites.)

If I have to use very general selectors (eg. #box) to customize a given website, that style might unintentionally affect other websites that have that same generic selector. Is there a way to specify a domain with a selector so I can my custom styles for each website separate?

I also found @-moz-document which looks good, but is Mozilla-specific and I use a WebKit browser. Is there an equivalent?

@-moz-document url(https://www.example.com/decrypt.php) {
like image 331
zekel Avatar asked Mar 16 '11 20:03

zekel


People also ask

How do I apply a CSS to a specific element?

The CSS id Selector To select an element with a specific id, write a hash (#) character, followed by the id of the element.

What is the use of pseudo-class host context () related specifically to custom elements?

The :host-context() CSS pseudo-class function selects the shadow host of the shadow DOM containing the CSS it is used inside (so you can select a custom element from inside its shadow DOM) — but only if the selector given as the function's parameter matches the shadow host's ancestor(s) in the place it sits inside the ...

Can you chain CSS selectors?

Any Selector Can Be Grouped You can place any valid selector in a group, and all elements in the document that match all the grouped elements will have the same style based on that style property.

Can NAV be a selector?

selector descendant-selector, e.g. nav a . This applies to all descendants of the selected kind that have the selected ancestor. a:link, a:visited, a:hover and a:active. These pseudo-selectors allow you to style hyperlinks based on their state.


1 Answers

Is the CSS hosted on a server that also allows you to script? Have you tried writing a server-side script to generate the correct CSS rules depending on the host that's serving the page?

Edit added March 30 2010:

You might be better off using the Greasemonkey extension to do this. It's far more powerful than user-defined stylesheets since you can use JavaScript, and adding domain or page-specific rules is as easy as adding special tags to the comments in the header. Greasemonkey was made specifically for handling your type of problem, and while you need a plugin to run Greasemonkey scripts in Firefox, Chrome ships with Greasemonkey support built-in.

like image 70
Adam Fabicki Avatar answered Oct 01 '22 09:10

Adam Fabicki