CSS syntax is described more fully in the Using CSS syntax in the
style sheet topic of the JViews
Diagrammer documentation.
The main elements of syntax are:
- Style rule
-
A CSS document, or style sheet, consists
of a set of style rules. Each style rule starts with a selector
and is followed by a declaration.
- Selector
-
A selector is composed of one or more
simple selectors. A simple selector is made of minimal building
blocks. When two or more simple selectors are aggregated into a
selector, they are separated by combinators. A combinator is a
single character; extra spaces are ignored.
- Declaration
-
Declarations are property-value pairs that are enclosed in
braces ({}). The separator is a colon (:). Each declaration is
terminated by a semicolon (;). The property represents a
predefined graphic attribute and the value is a literal, with
its type dependent on the property. All property-value pairs are
String
.
- Priority
-
Priority depends on specificity. Specificity is computed as
three numbers,
a-b-c
(in a number system with a large base). The number of ID
building blocks in the selector gives the first number
a
, the number of classes and attributes gives
b
, and the number of element types gives
c
.
- Cascading
-
Cascading consists in supplying several
sources for the style: the browser, the user, and the document
in HTML environments. Each source is weighted in relation to the
others, with document style taking precedence over user style,
which takes precedence over browser style when the specificity
is the same. CSS can also make use of internal cascading, when
it imports other style sheets by referring to a URL.
- Inheritance
-
Inheritance of declarations occurs when matched declarations are
sorted according to the priority of the rules and declarations
are merged. Higher priority settings override lower ones as
described in
The priority of CSS rules.