CSSStyleSheet

Overview

CSSStyleSheet is a class in Aspose.Html FOSS for Python.

Minimal CSSOM stylesheet object (CSSOM §6.4).

This class provides 7 methods for working with CSSStyleSheet objects in Python programs. Available methods include: __init__, add_rule, delete_rule, from_text, insert_rule, remove_rule, replace_sync. All public members are accessible to any Python application after installing the Aspose.Html FOSS for Python package. Properties: css_rules, css_text, disabled, href, media, owner_node, and 4 more.

Properties

NameTypeAccessDescription
hrefstr | NoneRead/WriteURL of this stylesheet, or None for inline sheets (CSSOM §6.4).
titlestrReadThe title of this stylesheet (CSSOM §6.4).
disabledboolReadWhether this stylesheet is disabled (CSSOM §6.4).
owner_ruleCSSRule | NoneReadThe @import rule that owns this sheet, or None (CSSOM §6.4).
mediastrReadThe media query string for this stylesheet (CSSOM §6.4).
parent_style_sheet"CSSStyleSheet | None"ReadThe stylesheet that imported this one via @import, or None (CSSOM §7.2.1).
rules"CSSRuleList"ReadLegacy alias for css_rules (CSSOM §7.2.1 historical).
css_textstrReadSerialise the stylesheet to a CSS text string (CSSOM §6.6).
css_rules``ReadGets the css rules.
owner_nodeobject | NoneReadGets the owner node.

Methods

SignatureDescription
__init__()Calls init on this CSSStyleSheet instance.
add_rule(selector: str, style: str, index: int)intInsert a new rule (legacy Netscape/IE form) — delegates to insert_rule.
remove_rule(index: int)Remove the rule at index (legacy Netscape/IE form) — delegates to delete_rule.
from_text(css_text: str, title: str, href: str | None, media: str)"CSSStyleSheet"Create a CSSStyleSheet from a CSS text string.
replace_sync(css_text: str)Replace stylesheet contents from CSS text.
insert_rule(rule_text: str, index: int | None)intParse rule_text and insert it at index in :attr:css_rules.
delete_rule(index: int)Remove the rule at index from :attr:css_rules.

See Also