什么命名空间应该在Firefox的userContent.css中定义? [英] What namespace should be defined in Firefox's userContent.css?

查看:202
本文介绍了什么命名空间应该在Firefox的userContent.css中定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Firefox的userChrome.css中,需要定义XUL命名空间:

lockquote
@namespace url( http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul

在userContent.css中,如果 about:addons 自定义是否包含在网站定制中?

仅指定:


@namespace url( http://www.w3.org/1999/xhtml );


会导致 about:addons 个自定义项无法应用。



(见为什么关于:addons p的CSS声明为什么 about:addons 自定义被放置在userContent.css中),所以在userContent而不是userChrome中放置了

解决方案 userContent.css 文件用于可以是任何名称空间的内容。最常用的是用于HTML和XUL。此外,Firefox正在过渡到在代码中使用更多的HTML命名空间元素,这些元素用于定义它们的chrome(即所有不是内容的东西)。因此,您需要同时处理 userChrome.css userContent.css 中的HTML和XUL。

考虑到Firefox Chrome中使用的HTML和XUL的混合,我发现我经常需要查看元素的源代码或者使用 DOM Inspector 查看哪个命名空间用于元素I 'm感兴趣。



有许多方法可以用 @namespace 指令。如果需要,以下两种方法都可以在同一个文件中使用。如果你这样做,你需要注意你定义的当前默认名称空间。



为HTML元素定义规则,将默认值更改为XUL,然后执行XUL



假设这些文件默认使用HTML命名空间,我个人所做的就是在使用之前使用我的HTML命名空间规则:

/ *将默认命名空间设置为XUL。 * /
@namespace url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);

设置默认命名空间为XUL。我所有的XUL规则都放在命名空间更改之后。因此,它看起来像这样:


$ b

/ *将所有的HTML命名空间规则放在这里。 * /

/ *将默认命名空间设置为XUL。 * /
@namespace url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);

/ *将所有的XUL命名空间规则放在这里。 * /

您如何组织它取决于您。我这样做是因为在将默认命名空间更改为XUL之后,尝试显式使用HTML命名空间作为元素时遇到了问题。我发现明确指定每个元素的名称空间通常不会像我预期的那样工作,而且是后面的痛苦。因此,我将所有我使用的规则重新组织为HTML或XUL。另外,定义名称空间前缀,然后在所有元素上使用它们。

如果要通过为每个元素明确指定名称空间来完成此操作,则需要定义一个名称空间前缀。你可以使用类似的方法来做到这一点:

/ *将html命名空间设置为http:// www.w3.org/1999/xhtml * /
@namespace html url(http://www.w3.org/1999/xhtml);
/ *将xul命名空间设置为http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul * /
@namespace xul url(http://www.mozilla .ORG /钥匙大师/关守/ there.is.only.xul);

您可以使用 html | xul | * | 来指定每个元素的HTML,XUL或所有名称空间。
$ b注意:一旦你改变了默认的命名空间,你可能需要明确地处理其他命名空间中的元素(例如< svg> < math> 等),通常会自动处理。


In Firefox's userChrome.css, it is necessary to define the XUL namespace:

@namespace url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);

In userContent.css, what namespace should be defined if about:addons customizations are included in addition to website customizations?

Specifying only:

@namespace url(http://www.w3.org/1999/xhtml);

results in the about:addons customizations not getting applied.

(See Why are CSS declarations for about:addons placed in userContent and not userChrome, given that the namespace is XUL? for why about:addons customizations get placed in userContent.css.)

解决方案

The userContent.css file is used for content that can be of any namespace. Most commonly it is used for both HTML and XUL. In addition, Firefox is transitioning to use more HTML namespace elements in the code which is used to define their chrome (i.e. everything that's not content). Thus, you will need to handle both HTML and XUL in both userChrome.css and userContent.css.

Given the mix of HTML and XUL used in Firefox Chrome, I find that I will often need to either look at the source code for the elements or use the DOM Inspector to see which namespace is being used for the elements I'm interested in.

There are many ways to do this with the @namespace directive. The following two approaches can both be used in the same file, if desired. If you do, you will need to pay attention to what you have defined as the current default namespace.

Define rules for HTML elements, change the default to XUL then do XUL

Given that these files, by default, use the HTML namespace, what I, personally, have done is just have my HTML namespace rules prior to using:

/* Set default namespace to XUL. */
@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");

to set the default namespace to XUL. All of my XUL rules are then placed after the namespace change. Thus, it looks something like:

/* Put all HTML namespace rules here. */    

/* Set default namespace to XUL. */
@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); 

/* Put all XUL namespace rules here. */    

How you organize it is up to you. I do it this way because I encountered issues when trying to explicitly use the HTML namespace for elements after changing the default namespace to XUL. I found that explicitly specifying the namespace per element often did not function as I expected, and was a pain the the rear. Thus, I restructured all of the rules I use to be exclusively either HTML or XUL.

Alternately, define namespace prefixes, then use them on all elements

If you want to do it by explicitly specifying the namespace for each element, you will want to define a namespace prefix. You can do so by using something like:

/* set html namespace to http://www.w3.org/1999/xhtml */
@namespace html url("http://www.w3.org/1999/xhtml");
/* set xul namespace to http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul */
@namespace xul url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");

You can then use html|, xul| or *| to specify the HTML, XUL, or all namespaces for each element.

Note: Once you change the default namespace, you may need to explicitly deal with elements in other namespaces (e.g. <svg>, <math>, etc.), which would normally be handled automatically.

这篇关于什么命名空间应该在Firefox的userContent.css中定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆