Rule

Class

A CSS style rule. A block is created with provided selector(s), which can then have individual key/value rules written to it.

Basic rules can be created with the constructor. Advanced rules can be created via the static methods.

These rules can be written into a style element.

Extends

Object

Implements

Writable

Modifiers

public

Rule.of(DIV).rule("border-bottom", "2px solid black")
Rule.of(P, Qualifier.ATTRIBUTE_EQUALS.of("blob", "hello")).rule("color", "blue")
new Rule(DIV).rule("background", "red")

Constructors


new Rule (Object...)

Constructor

A rule with multiple selectors. These will be written as first second third {...}.

This can accept HTMElements or string tag names.

IndexTypeName
1Object[]object
Return Type

Rule

Modifiers

public varargs

// Randomly-generated example
final Rule rule = new Rule(object);
assert rule.write(stream, charset) == null;
rule.rule(key, value);
rule.rule(key, value, important);

new Rule (String...)

Constructor

A rule with multiple selectors. These will be written as first second third {...}.

IndexTypeName
1String[]string
Return Type

Rule

Modifiers

public varargs

// Randomly-generated example
final Rule rule = new Rule(string);
assert rule.write(stream, charset) == null;
rule.rule(key, value);
rule.rule(key, value, important);

Methods


of (HTMElement)

Method

Writes a simple selector for this element's tag.

IndexTypeName
1HTMElementelement
Return Type

Rule

Modifiers

public static

of (HTMElement, TargetQualifier)

Method

Writes a new selector with an advanced qualifier. These can be simple tags such as p::before or advanced attribute selectors like div[name=bean].

These can be written using the Qualifier enum.

IndexTypeName
1HTMElementbefore
2TargetQualifierqualifier
Return Type

Rule

Modifiers

public static

Rule.of(DIV, ATTRIBUTE_EQUALS.of("name", "hello"))
div[name=hello] {
}

of (String, TargetQualifier)

Method

Writes a selector for the string tag with a qualifier.

This can be used to build complex selectors.

IndexTypeName
1Stringbefore
2TargetQualifierqualifier
Return Type

Rule

Modifiers

public static

of (TargetQualifier)

Method

Writes a selector for a qualifier.

This can be used to select special elements.

IndexTypeName
1TargetQualifierqualifier
Return Type

Rule

Modifiers

public static

before (HTMElement, HTMElement)

Method

Writes a new selector for tags immediately before each other.

IndexTypeName
1HTMElementbefore
2HTMElementafter
Return Type

Rule

Modifiers

public static

Rule.before(UL, P)
p ~ ul {
}

after (HTMElement, HTMElement)

Method

Writes a new selector for tags immediately after each other.

IndexTypeName
1HTMElementbefore
2HTMElementafter
Return Type

Rule

Modifiers

public static

Rule.after(UL, P)
ul + p {
}

child (HTMElement, HTMElement)

Method

Writes a new selector for child tags inside an immediate parent tag.

IndexTypeName
1HTMElementparent
2HTMElementchild
Return Type

Rule

Modifiers

public static

Rule.child(DIV, P)
div > p {
}

all (HTMElement...)

Method

Writes a selector for all of the given elements.

IndexTypeName
1HTMElement[]elements
Return Type

Rule

Modifiers

public static varargs

Rule.all(UL, P, DIV, BR)
ul, p, div, br {
}

rule (String, String)

Method

Adds a new rule to the block.

IndexTypeName
1Stringkey
2Stringvalue
Return Type

Rule

Modifiers

public

new Rule(DIV).rule("background", "red")
div {
    background: red;
}

rule (String, String, boolean)

Method

Adds a new rule to the block with the !important tag.

IndexTypeName
1Stringkey
2Stringvalue
3booleanimportant
Return Type

Rule

Modifiers

public

new Rule(DIV).rule("background", "red", true)
div {
    background: red !important;
}

inside (HTMElement, HTMElement)

Method

Writes a new selector for inner tags inside an outer tag.

IndexTypeName
1HTMElementouter
2HTMElementinner
Return Type

Rule

Modifiers

public static

Rule.inside(DIV, P)
div p {
}

everything ()

Method

Writes a selector for everything.

Return Type

Rule

Modifiers

public static

Rule.everything()
* {
}