StyleSheet

Package: Libraries.Web.Styles · Inherits from: Libraries.Language.Object

StyleSheet holds the rules of one stylesheet and writes them as text. Each rule gives a class name and the declarations that go with it, and an element uses only one plain rule, so plain rules never compete. After the plain rules come rules that apply only in a state (while the pointer is over an element, or while it has focus), then rules for wider screens, narrowest first, and last the named rules scripts add and remove. Each later kind changes only what it sets, on top of an element's plain rule. A stylesheet can start with a reset that clears browsers' own spacing. A WebSite builds one for the whole site from its pages; people making pages don't use it directly.

Example Code

use Libraries.Web.Styles.StyleSheet

StyleSheet sheet
sheet:AddRule("q1", "display:flex;flex-direction:column;")
output sheet:Generate()

Actions

AddRule(text className, text declarations)

Adds a plain rule: every element with this class name gets these declarations. A class name can have only one rule.

Parameters

  • className text: The class name, without the leading dot.
  • declarations text: The declarations, such as "display:flex;".

AddScriptRule(text className, text declarations)

Adds a rule with a name a page's scripts use, written after every other rule so it wins while an element has it.

Parameters

  • className text: The name, without the leading dot.
  • declarations text: The declarations.

AddStateRule(text className, text declarations, text state)

Adds a rule that applies only in a state, such as ":hover", or in surroundings, such as ":disabled " (a state ending in a space, for an element inside a disabled control).

Parameters

  • className text: The class name, without the leading dot.
  • declarations text: The declarations.
  • state text: The state, such as ":hover" or ":focus".

AddWidthRule(text className, text declarations, number pixels)

Adds a rule that applies only on screens at least this wide.

Parameters

  • className text: The class name, without the leading dot.
  • declarations text: The declarations.
  • pixels number: The narrowest screen the rule applies on.

Generate()

Returns the whole stylesheet as text, one rule per line: the reset if asked for, the motion rules, plain rules, state rules, then rules for each screen width from narrowest, then script rules. Each group is sorted by class name, so the same rules always give the same file.

Returns

text: The stylesheet's text.

SetReset(boolean value)

Sets whether the stylesheet starts with the reset.

Parameters

  • value boolean: True to start with the reset.

Inherited Actions

3 actions from Libraries.Language.Object