author: | $LastChangedBy: cthedot $ |
---|---|
date: | $LastChangedDate: 2007-08-08 16:14:03 +0200 (Mi, 08 Aug 2007) $ |
version: | $LastChangedRevision: 206 $ |
Contents
A CSSStyleDeclaration contains all properties set in a CSSStyleRule or CSSPageRule.
Example:
/* a comment */ color: red; /* properties might be set more than once for different UAs */ c\\olor: green; background-color: #fff
a parsable textual representation of the declaration. See also:
The following methods all have a parameter normalize which if set to False results in handling of name not being normalized. Default behaviour is to always access the effective property in this rule (the last set). An un-normalized name like c\\olor gives access to the property with this actual name. To work on all properties it is probably easiest to iterate directly over all properties or to use getProperties().
CSSStyleDeclaration implements CSS2Properties so most CSS 2 properties may be used like:
declaration.color = 'red' declaration.backgroundColor = '#000'
As some properties contain a "-" character these have to be used in camelcase instead!
cssutils implements only a subset of CSS2Properties so setting e.g. declaration.border = '1px solid red' does only set border but not border-style, border-color etc which it should. This may be implemented later.
CSSStyleDeclaration is iterable (experimental). The iterator returns all properties set in this style as objects with properties name, cssValue and priority. Calling CSSStyleDeclaration.item(index) on the other hand simply returns a property name and also only the normalized name (once). Example:
sheet = cssutils.parseString('a { color: red; c\olor: blue; left: 0 !important }') for rule in sheet.cssRules: style = rule.style for property in style: name = property.name cssValue = property.cssValue priority = property.priority print name, '=', cssValue.cssText, priority # prints: # color = red # c\olor = blue # left = 0 !important for i in range(0, style.length): name = style.item(i) cssValue = style.getPropertyCSSValue(name) priority = style.getPropertyPriority(name) print name, '=', cssValue.cssText , priority # prints: # color = blue # left = 0 !important
A Property is used in a CSSStyleDeclaration but also in a MediaQuery object. Only in the latter case a value is optional and a priority not used at all. As MediaQuery is not a finished spec so some details may still change.
A property has the following attributes: