---
title: XUL element attributes
slug: XUL_element_attributes
tags:
- XUL Attributes
translation_of: Archive/Mozilla/XUL/XUL_Reference/XUL_element_attributes
---
« XUL Reference home The following attributes are common to all XUL elements:
align
- Type: one of the values below
- The align attribute specifies how child elements of the box are aligned, when the size of the box is larger than the total size of the children.
当box的尺寸大于全部子元素的尺寸时,align属性指定box元素的对齐方式。
- For boxes that have horizontal orientation, it specifies how its children will be aligned vertically.
- 当box设置水平排列,它指定子元素如何垂直对齐。
- For boxes that have vertical orientation, it specifies how its children will be aligned horizontally.
- 当box设置垂直排列,它指定子元素如何水平对齐
-
start
- Child elements are aligned starting from the left or top edge of the box. If the box is larger than the total size of the children, the extra space is placed on the right or bottom side.
子元素从box的左边或顶部开始排列。如果box大于全部子元素的总和,多出的空间在右边或底部。
center
- Extra space is split equally along each side of the child elements, resulting in the children being placed in the center of the box.
多出的空间在子元素的周围,使子元素放置在box的中间。
end
- Child elements are placed on the right or bottom edge of the box. If the box is larger than the total size of the children, the extra space is placed on the left or top side.
子元素从box的右边或底部开始排列。如果box大于全部子元素的总和,多出的空间在左边或顶部部。
baseline
- This value applies to horizontally oriented boxes only. It causes the child elements to be aligned so that their text labels are lined up.
这个值只适用于水平方向的box元素。它让子元素的文本标签成一条直线。
stretch
- This is the default value. The child elements are stretched to fit the size of the box. For a horizontal box, the children are stretched to be the height of the box. For a vertical box, the children are stretched to be the width of the box. If the size of the box changes, the children stretch to fit. Use the flex attribute to create elements that stretch in the opposite direction.
这是默认值。拉伸子元素来填充box。在水平的box元素中,子元素在高度上被拉伸。在垂直的box元素中,子元素在宽度上被拉伸。如果box元素尺寸改变,子元素也随之改变。使用flex属性创建的元素在相反方向被拉伸。
left
- The elements are aligned on their left edges.
元素左边缘对齐。
center
- The elements are centered horizontally.
元素水平居中。
right
- The elements are aligned on their right edges.
元素右边缘对齐。
- The pack attribute is related to the alignment but is used to specify the position in the opposite direction. You can also specify the value of align using the style property
-moz-box-align
.
pack也是有关对齐的属性,但是指定相反方向的位置。你也可以在style中使用对齐的方式-moz-box-align
。
allowevents
- Type:
boolean
类型:boolean
- If true, events are passed to children of the element. Otherwise, events are passed to the element only.
如果为真,事件向子元素传递。否则,事件只传递到当前元素。
allownegativeassertions
- Type: boolean
类型:布尔类型
- Valid on any element that has a
datasources
attribute. When multiple datasources are used, one may override an assertion from another. This attribute, if true
, which is the default, allows a datasource to negate an earlier assertion.
适用于任何有 datasources
属性的元素。当使用多个数据源,一个数据源可以指定覆盖另一个。这个属性,如果为真,这是默认值,允许一个数据源覆盖之前的数据源。
class
- Type:
string
类型:字符串(string)
- The style class of the element. Multiple classes may be specified by separating them with spaces.
元素样式类型。多个类可以使用空格分开。
coalesceduplicatearcs
- Type: boolean
类型:布尔类型(boolean)
- Valid on any element that has a
datasources
attribute. When multiple datasources are used, one may override an assertion from another. This attribute, if true
, which is the default, allows a datasource to negate an earlier assertion.
任何有 datasources
属性的元素有效。当有多个数据源时使用,可以覆盖另一个声明。这个属性,如果是真,这是默认属性,允许一个数据源取消更早的声明。
collapsed
- Type: boolean
类型:布尔类型(boolean)
- If
true
, then the element is collapsed and does not appear. It is equivalent to setting the CSS visibility property to collapse
.
如果是真,那么这个元素可以折叠并且隐藏。相当于设置CSS的 visibility 属性为 collapse。
container
- Type: boolean
类型:布尔类型(boolean)
- Set to true if the element is to act as a container which can have child elements. This would be used for folders. This will be set by the template builder as needed.
如果该元素是作为一个容器可以有子元素,设置为真。
containment
- Type: URI
- This attribute specifies RDF properties (an RDF predicate) that indicate that a resource is a container. When generating content from a template this is used to determine which resources from the datasource are containers and thus can have child nodes and which ones are not containers.
- This attribute should be placed on the same element that the
datasources
and the ref
attribute is on. It may be set to a space-separated list of RDF properties or resources.
context
- Type: id
- Should be set to the value of the id of the popup element that should appear when the user context-clicks on the element. A context-click varies on each platform. Usually it will be a right click. You can use the special value '_child' to indicate the first
menupopup
child of the element.
datasources
- Type: space separated list of datasource URIs
- A space-separated list of datasources that an element's template will use for content generation. These can be either internal datasources such as rdf:bookmarks or a URL. The datasources attribute may be placed on most elements, although it will usually be found on trees and menu related elements. The element should have a
template
element as a child.
- For RDF templates, the specified datasources are combined into a single composite datasource which holds the data from all of the datasources. This composite datasource is accesssible via a script through the database property.
- For XML datasources, only one source is used, either the URL of an XML file or an anchor reference to another element within the same document. For instance, the reference '#data' refers to an element with the id 'data'.
- If you plan on adding a datasource to an element but don't want one to be added right away, set this attribute to 'rdf:null'. This will make the element so that its contents can be generated from a datasource. Otherwise, you cannot add one later.
- When the XUL document is contained on a remote web site, the datasources may only be loaded from the same domain as the document.
-
dir
-
Type:
one of the values below
-
The direction in which the child elements of the element are placed.
-
normal
-
For scales, the scale's values are ordered from left to right (for horizontal scales) or from top to bottom (for vertical scales) For other elements, the elements are placed left to right or top to bottom in the order they appear in the XUL code
-
reverse
-
For scales, the scale's values are ordered from right to left (for horizontal scales) or from bottom to top (for vertical scales). For other elements, they are placed right to left or bottom to top. This is reverse of the order in which they appear in the XUL code.
empty
- Type: boolean
- Set to true if the element is a container that contains no children. This will be set by the template builder as needed.
equalsize
- Type: one of the values below
- This attribute can be used to make the children of the element equal in size.
always
- For a horizontally oriented element, this will make all of its children have the width of the widest child. For a vertically oriented element, this will make its children all have the height of the tallest child.
never
- All of the children are displayed at the size required by the content or as specified by the
width
and height
attributes or the CSS width
and height
properties.
flags
- Type: space-separated list of the values below
- A set of flags used for miscellaneous purposes. Two flags are defined, which may be the value of this attribute.
dont-test-empty
: For template generated content, the builder will not check that a container is empty.
dont-build-content
: This flag may be used on a tree to indicate that content elements should not be generated. This results in a performance enhancement, but you will not be able to use the DOM functions to retrieve the tree rows.
flex
- Type: string (representing an integer)
类型:字符串 (string) 表示一个整数
- Indicates the flexibility of the element, which indicates how an element's container distributes remaining empty space among its children. Flexible elements grow and shrink to fit their given space. Elements with larger flex values will be made larger than elements with lower flex values, at the ratio determined by the two elements. The actual value is not relevant unless there are other flexible elements within the same container. Once the default sizes of elements in a box are calculated, the remaining space in the box is divided among the flexible elements, according to their flex ratios. Specifying a flex value of 0 has the same effect as leaving the flex attribute out entirely.
指示一个元素的伸缩性,
height
- Type: string (representing an integer)
- The preferred height of the element in pixels. The actual displayed height may be different if the element or its contents have a minimum or maximum height. The CSS height property may also be used.
hidden
- Type: boolean
- If set to true, the element is not displayed. This is similar to setting the CSS display property to 'none'.
-
id
-
类型: 元素的ID,在主窗口中必须唯一
-
一个唯一的标识一边开发者能够定义. 你可以使用方法
getElementById()
或者其他 DOM 的函数并在样式表中添加对元素的引用。
insertafter
- Type: id
- When an element is in an
overlay
, the insertafter attribute specifies the id
of the element in the base window that the element should appear after. This attribute overrides the insertbefore
attribute. This value may be a comma-separated list of ids, which are scanned and the first one found in the window is used.
insertbefore
- Type: id
- When an element is in an
overlay
, the insertbefore attribute specifies the id
of the element in the base window that the element should appear before. This value may be a comma-separated list of ids, which are scanned and the first one found in the window is used.
left
- Type: string (representing an integer)
- For elements placed directly within a
stack
, specifies the pixel position of the left edge of the element relative to the left edge of the stack.
maxheight
- Type: string (representing an integer)
- The maximum height of the element. This corresponds to the max-height CSS property.
maxwidth
- Type: string (representing an integer)
- The maximum width of the element. This corresponds to the max-width CSS property.
minheight
- Type: string (representing an integer)
- The minimum height of the element. This corresponds to the min-height CSS property.
minwidth
- Type: string (representing an integer)
- The minimum width of the element. This corresponds to the min-width CSS property.
mousethrough
- Type: one of the values below
- Determines whether mouse events are passed to the element or not. If this attribute is not specified, the value is inherited from the parent of the element. If no ancestor has the mousethrough attribute set, the default value is
never
.
always
- Mouse events are transparent to the element. This means that the element will not receive any mouse events due to either clicking or movement. Child elements may override this if they specify mousethrough="never".
never
- Mouse events are passed to the element as normal.
observes
- Type: id
- Set to an id of a
broadcaster
element that is being observed by the element. If an attribute changes in the broadcaster it is also changed in the observer.
ordinal
- Type: string (representing an integer)
- An integer which specifies the position of the element within its parent. By default, elements appear in the order they appear in the XUL code. The ordinal attribute can be used to change the order. Note the default ordinal for elements is 1. You can retrieve the displayed order by using the properties of the
boxObject
of the container.
布局(orient)
-
值类型:可以是下面值中的一种。
指定了子控件的布局(orient)为水平分布的(horizontally)或者是垂直分布的(vertically)。默认值依赖于控件本身。你也可以使用-moz-box-orient中的样式属性。
- horizontally: 子控件会被按照在xul源文件中出现的位置依次布置在一行中。
- vertically: 子控件会被按照在xul源文件中出现的位置依次布置在一列中。
pack
- Type: one of the values below
- The pack attribute specifies where child elements of the
box
are placed when the box is larger that the size of the children. For boxes with horizontal orientation, it is used to indicate the position of children horizontally. For boxes with vertical orientation, it is used to indicate the position of children vertically. The align
attribute is used to specify the position in the opposite direction. You can also specify the value of pack using the style property -moz-box-pack
.
start
- Child elements are placed starting from the left or top edge of the box. If the box is larger than the total size of the children, the extra space is placed on the right or bottom side.
center
- Extra space is split equally along each side of the child elements, resulting the children being placed in the center of the box.
end
- Child elements are placed on the right or bottom edge of the box. If the box is larger than the total size of the children, the extra space is placed on the left or top side.
-
persist
-
Type:
space-separated list of attribute names
-
A space-separated list of attributes that are maintained when the window is closed. When the window is re-opened, the values of persistent attributes are restored. In Mozilla, persistent attributes are stored in the per-profile file
localstore.rdf
. Persistence can also be stored using the document.persist
function. In order for persistence to work, the element must also have an id
.
position
- Type: string (representing an integer)
- When an element is in an
overlay
, the position is an index where the child is inserted. The position is one-based, so use a value of 1 to place the element at the beginning. This attribute is ignored if either an insertbefore
or insertafter
attribute matches an element.
preference-editable
- Mozilla 1.8
- Type: boolean
- If
true
, the element may be used as one that modifies a preference in a prefwindow
. The preference
attribute may be used to connect to a preference
element. This is useful for custom elements implemented in XBL. The element should fire change
, command
, or input
event when the value is changed so that the preference will update accordingly.
See the pref system documentation for more information.
querytype
- Type: string
- Indicates the type of datasource used in a template. Firefox 3 provides 3 built-in datasources: 'rdf', default, 'xml' and 'storage'. Extensions may provide support for additional datasources.
ref
- Type: URI
- For template-generated elements, this attribute is used to specify the root RDF node where content generation begins. This will correspond to the value of an about attribute on an RDF container. This attribute should be placed alongside the datasources attribute.
removeelement
- Type: id
- When placed on an element in an
overlay
, it indicates that the element in the base file should be removed from the window.
sortDirection
- Type: one of the values below
- Set this attribute to set the direction that template-generated content is sorted. Use the
sortResource
attribute to specify the sort key.
ascending
- The data is sorted in ascending order.
descending
- The data is sorted in descending order.
natural
- The data is sorted in natural order, which means the order that it is stored in.
sortResource
- Type: URI
- For template-generated content, this specifies the sort key, if you would like the content to be sorted. The key should be the full URI of the RDF resource to sort by, for example '
http://home.netscape.com/NC-rdf#Name
'. Place this attribute on the same element as the datasources
attribute. Use sortResource2
to specify a secondary sort key.
sortResource2
- Type: URI
- The value of this attribute is the URI of an RDF predicate that serves as a secondary key for sorted content.
statustext
- Type: string
- Used to set the text that appears on the status bar when the user moves the mouse over the element. Mozilla doesn't adjust the status bar automatically however. This attribute serves only as a place to keep the text. In Firefox, this text is automatically placed in the
statusbar
for menuitems on the menu bar.
style
- Type: CSS inline style
- CSS style rules to be applied to the element. Syntax is as in the HTML style attribute. It is preferred to put style rules in style sheets.
template
- Type: id
- For template generated elements, this attribute may optionally be placed on the root node (the element with the
datasources
attribute) to refer to a template that exists elsewhere in the XUL code. This template attribute should be set to the id
of the template
element. This might be used to share a single template between multiple trees or menus. If this attribute is not specified, there should be a template element directly inside the node.
tooltiptext
- Type: string
- Used to set the text which appears in the tooltip when the user moves the mouse over the element. This can be used instead of setting the tooltip to a popup for the common case where it contains only text. The tooltip is displayed in a default tooltip which displays only a label, however the default tooltip may be changed by setting the default attribute on a
tooltip
element.
top
- Type: string (representing an integer)
- For elements placed directly within a
stack
, specifies the pixel position of the top edge of the element relative to the top edge of the stack.
uri
- Type: string
- For template-generated content, the attribute should be placed on the element where content generation should begin. Thus, it should be placed on an element that is a descendant of a template. The value should be set to
rdf:*
.
- Elements that appear inside the element with the attribute will be repeated for each node in the RDF datasource. Elements outside will appear only once.
-
wait-cursor
-
Type: boolean
-
Set this attribute to true to have the cursor switch to a waiting cursor while the mouse is hovering over the element. Usually, you would only use this on the
window
element or other top-level elements. In order to revert to the normal cursor state call the method removeAttribute("wait-cursor")
when the process effectively has ended otherwise the wait cursor might never disappear.
width
- Type: string (representing an integer)
- The preferred width of the element. The value should not include a unit as all values are in pixels. The actual displayed width may be different if the element or its contents have a minimum or maximum width, or the size is adjusted by the flexibility or alignment of its parent. The CSS width property may also be used.