CSS Variables

CSSVariablesRule

class cssutils.css.CSSVariablesRule(mediaText=None, variables=None, parentRule=None, parentStyleSheet=None, readonly=False)

The CSSVariablesRule interface represents a @variables rule within a CSS style sheet. The @variables rule is used to specify variables.

cssutils uses a CSSVariablesDeclaration to represent the variables.

Format:

variables
    VARIABLES_SYM S* medium [ COMMA S* medium ]* LBRACE S* 
    variableset* '}' S*
    ;

for variableset see cssutils.css.CSSVariablesDeclaration

Media are not implemented. Reason is that cssutils is using CSS variables in a kind of preprocessing and therefor no media information is available at this stage. For now do not use media!

Example:

@variables {
  CorporateLogoBGColor: #fe8d12;
}

div.logoContainer {
  background-color: var(CorporateLogoBGColor);
}
atkeyword
Literal keyword of an @rule (e.g. @IMport).
cssText
(DOM) The parsable textual representation of this rule.
parent
The Parent Node of this CSSRule or None.
parentRule
If this rule is contained inside another rule (e.g. a style rule inside an @media block), this is the containing rule. If this rule is not nested inside any other rules, this returns None.
parentStyleSheet
The style sheet that contains this rule.
seq
Internal readonly attribute, DO NOT USE!
type
The type of this rule, as defined by a CSSRule type constant.
typeString
Descriptive name of this rule's type.
valid
TODO
variables
(DOM) The variables of this rule set, a CSSVariablesDeclaration.

CSSVariablesDeclaration

class cssutils.css.CSSVariablesDeclaration(cssText=u'', parentRule=None, readonly=False)

The CSSVariablesDeclaration interface represents a single block of variable declarations.

cssText
(DOM) A parsable textual representation of the declaration block excluding the surrounding curly braces.
getVariableValue(variableName)

Used to retrieve the value of a variable if it has been explicitly set within this variable declaration block.

Parameter:variableName -- The name of the variable.
Returns:the value of the variable if it has been explicitly set in this variable declaration block. Returns the empty string if the variable has not been set.
item(index)

Used to retrieve the variables that have been explicitly set in this variable declaration block. The order of the variables retrieved using this method does not have to be the order in which they were set. This method can be used to iterate over all variables in this variable declaration block.

Parameter:index -- of the variable name to retrieve, negative values behave like negative indexes on Python lists, so -1 is the last element
Returns:The name of the variable at this ordinal position. The empty string if no variable exists at this position.
keys()
Analoguous to standard dict returns variable names which are set in this declaration.
length
The number of variables that have been explicitly set in this variable declaration block. The range of valid indices is 0 to length-1 inclusive.
parentRule
(DOM) The CSS rule that contains this declaration block or None if this block is not attached to a CSSRule.
removeVariable(variableName)

Used to remove a variable if it has been explicitly set within this variable declaration block.

Parameter:

variableName -- The name of the variable.

Returns:

the value of the variable if it has been explicitly set for this variable declaration block. Returns the empty string if the variable has not been set.

Exceptions:
seq
Internal readonly attribute, DO NOT USE!
setVariable(variableName, value)

Used to set a variable value within this variable declaration block.

Parameters:
  • variableName -- The name of the CSS variable.
  • value -- The new value of the variable, may also be a CSSValue object.
Exceptions:
  • SyntaxErr: Raised if the specified value has a syntax error and is unparsable.
  • NoModificationAllowedErr: Raised if this declaration is readonly or the property is readonly.

CSSVariable

class cssutils.css.cssvalue.CSSVariable(cssText=None, parent=None, readonly=False)

The CSSVariable represents a call to CSS Variable.

cssText
A string representation of the current variable.
value
Find contained sheet and @variables there

Table Of Contents

Previous topic

Package cssutils.css

Next topic

Package cssutils.stylesheets