有没有办法让 CSS 选择器应用于特定主机? (对于我的自定义浏览器样式表。)
我想将样式(编辑:在我的浏览器的用户定义样式表中,这是我计算机上的本地文件,让我自定义其他人的网站如何为我呈现)到特定网站,但是许多网页通常都是通用的(显然超出了我的控制范围,因为它们不是我的网站。)
如果我必须使用非常通用的选择器(例如#box)来自定义给定的网站,则该样式可能会无意中影响其他网站具有相同的通用选择器。有没有办法使用选择器指定域,以便我可以为每个网站单独设置自定义样式?
我还发现 @-moz-document 看起来不错,但它是 Mozilla 特定的,我使用 WebKit 浏览器。有同等的吗?
@-moz-document url(https://www.example.com/decrypt.php) {
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) {
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
CSS 是否托管在允许您编写脚本的服务器上?您是否尝试过编写服务器端脚本来根据为页面提供服务的主机生成正确的 CSS 规则?
2010 年 3 月 30 日添加的编辑:
您最好使用 Greasemonkey 扩展来执行此操作。它比用户定义的样式表强大得多,因为您可以使用 JavaScript,并且添加特定于域或页面的规则就像向标头中的注释添加特殊标签一样简单。 Greasemonkey 是专门为处理您的问题类型而设计的,虽然您需要一个插件来在 Firefox 中运行 Greasemonkey 脚本,但 Chrome 附带了内置的 Greasemonkey 支持。
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.
如果你可以使用 javascript 修改 HTML,那就有办法了。它可以是这样的(使用 JQuery):
然后,在你的 CSS 中,你可以这样做:
If you can modify the HTML using javascript, there would be a way. It could go something like this (using JQuery):
Then, in your CSS, you can do this:
考虑安装广告拦截器,例如 uBlockOrigin,然后编写一些自定义过滤器。您可以在“设置”->“设置”中添加这些自定义过滤器。我的过滤器。
Consider installing an ad blocker such as uBlockOrigin, then writing some custom filters. You can add these custom filters in Settings -> My Filters.
嗯,我认为 php 将是最合理的解决方案,而且实际上非常简单。
使用 php 来决定做什么/何时做什么,并在某些情况下回显某些 css 文件。
如果您需要更多帮助,请告诉我们更多有关您的问题的信息,我将为您编写完整的解决方案。
Uhm, I think php would be the most rational solution, and actually very easy.
Use php to decide what/when to do and echo certain css files in certain cases.
If you need more help, tell us more about your problem and I'll write the complete solution for you.