CSSStyleDeclaration class

The CSSStyleDeclaration interface represents an object that is a CSS declaration block, and exposes style information and various style-related methods and properties.

A CSSStyleDeclaration object can be exposed using three different APIs:

  1. Via HTMLElement.style, which deals with the inline styles of a single element (e.g.,
    ).
  2. Via the CSSStyleSheet API. For example, document.styleSheets0.cssRules0.style returns a CSSStyleDeclaration object on the first CSS rule in the document's first stylesheet.
  3. Via Window.getComputedStyle(), which exposes the CSSStyleDeclaration object as a read-only interface.

Constructors

CSSStyleDeclaration()
CSSStyleDeclaration.computedStyle(Element? target, Map<String, dynamic>? defaultStyle, StyleChangeListener? onStyleChanged)

Properties

cssText String
Textual representation of the declaration block. Setting this attribute changes the style.
no setter
defaultStyle Map<String, dynamic>?
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
length int
The number of properties.
no setter
onStyleChanged StyleChangeListener?
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
target Element?
getter/setter pair

Methods

addStyleChangeListener(StyleChangeListener listener) → void
contains(String property) bool
Check a css property is valid.
diff(CSSStyleDeclaration other) Map<String, String?>
dispose() → void
flushPendingProperties() → void
getPropertyValue(String propertyName) String
Returns the property value given a property name. value is a String containing the value of the property. If not set, returns the empty string.
item(int index) String
Returns a property name.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeProperty(String propertyName, [bool? isImportant]) → void
Removes a property from the CSS declaration.
removeStyleChangeListener(StyleChangeListener listener) → void
reset() → void
setProperty(String propertyName, String? value, [bool? isImportant]) → void
Modifies an existing CSS property or creates a new CSS property in the declaration block.
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited
operator [](String property) → dynamic
Override [] and []= operator to get/set style properties.
operator []=(String property, dynamic value) → void

Static Properties

empty CSSStyleDeclaration
An empty style declaration.
getter/setter pair

Static Methods

isNullOrEmptyValue(dynamic value) bool