An attribute can be rendered in the document view by inserting a value editor in the generated content.
XHTML example: a pair of radio buttons are used to set the dir
attribute of a p
of class bidi
.
p.bidi:after { display: block; content: "Direction: " radio-buttons(attribute, dir, labels, "Left to right\A Right to left", values, "ltr\A rtl"); font-size: smaller; }
This way of rendering attributes is fine but is too tedious to specify to be used on a large scale, for example to style XML data where most elements are empty but have several attributes.
In such case, it is recommended to use CSS rules where the selector contain the :attribute
() non-standard pseudo-element.
Same example as above but using this type of rule:
p.bidi2:after {display: block; content: attributes(); } p.bidi2::attribute(dir) {
attribute-content-left: "Direction:"; attribute-content-middle: radio-buttons(attribute, dir, labels, "Left to right\A Right to left", values, "ltr\A rtl"); show-attribute: always; font-size: smaller; }
![]() | First rule inserts an A The content of an |
![]() | Second rule specifies that attribute
|
Table 4.2. Properties used to specify generated content for attributes
Property | Value | Initial value | Description |
---|---|---|---|
attribute-content-left | Any value allowed for the content: property plus attribute-*() pseudo functions (see below). | "" (no content) | Generated content for the attribute which is the target of the :attribute() rule that goes to the left column of the attributes() container. |
attribute-content-middle | Any value allowed for the content: property plus attribute-*() pseudo functions (see below). | "" (no content) | Generated content for the attribute which is the target of the :attribute() rule that goes to the middle column of the attributes() container. |
attribute-content-right | Any value allowed for the content: property plus attribute-*() pseudo functions (see below). | "" (no content) | Generated content for the attribute which is the target of the :attribute() rule that goes to the right column of the attributes() container. |
show-attribute | never | always | when-added | when-added |
|
Same example as above with all attributes a p
of class bidi2
, displayed when they are added to this element, except for the dir
attribute which is always displayed:
p.bidi2:after { display: block; content: attributes(); } p.bidi2::attribute() {attribute-content-left: attribute-label() ":";
attribute-content-middle:
value-editor(attribute, attribute());
attribute-content-right: remove-attribute-button(attribute, attribute());
show-attribute: when-added; font-size: smaller; } p.bidi2::attribute(dir) {
attribute-content-left: "Direction:"; attribute-content-middle: radio-buttons(attribute, dir, labels, "Left to right\A Right to left", values, "ltr\A rtl"); show-attribute: always; }
Notice that in the above figure, the values of the dir
attribute are displayed in green. This is because, unlike in first example, this p
of class bidi2
has no dir
attribute yet.
By default (this can be specified):
A green foreground color means that attribute is not set.
A red foreground color means that attribute value is invalid or that the value editor is not well suited to display this kind of values.
![]() | This rule specifies the generated content for all attributes of a | |||||||||||||||
![]() |
Similar generated content is:
| |||||||||||||||
![]() |
| |||||||||||||||
![]() |
| |||||||||||||||
![]() | ||||||||||||||||
![]() | This rule specializes the previous rule for the |