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
| Name | Type | Access | Description |
|---|---|---|---|
href | str | None | Read/Write | URL of this stylesheet, or None for inline sheets (CSSOM §6.4). |
title | str | Read | The title of this stylesheet (CSSOM §6.4). |
disabled | bool | Read | Whether this stylesheet is disabled (CSSOM §6.4). |
owner_rule | CSSRule | None | Read | The @import rule that owns this sheet, or None (CSSOM §6.4). |
media | str | Read | The media query string for this stylesheet (CSSOM §6.4). |
parent_style_sheet | "CSSStyleSheet | None" | Read | The stylesheet that imported this one via @import, or None (CSSOM §7.2.1). |
rules | "CSSRuleList" | Read | Legacy alias for css_rules (CSSOM §7.2.1 historical). |
css_text | str | Read | Serialise the stylesheet to a CSS text string (CSSOM §6.6). |
css_rules | `` | Read | Gets the css rules. |
owner_node | object | None | Read | Gets the owner node. |
Methods
| Signature | Description |
|---|---|
__init__() | Calls init on this CSSStyleSheet instance. |
add_rule(selector: str, style: str, index: int) → int | Insert 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) → int | Parse rule_text and insert it at index in :attr:css_rules. |
delete_rule(index: int) | Remove the rule at index from :attr:css_rules. |