Styles
Styles are defined once in a palette and referenced by ID.
The palette
{
"styles": {
"defs": { "header_bold": { "font_weight": "bold" } },
"compositions": { "header_right": { "extends": "header_bold", "overrides": { "text_align": "right" } } },
"conditionals": [{ "id": "stripe", "selector": { "row_parity": "even" }, "style": { "background_color": "#FAFAFA" } }]
}
}| Field | Type | Default | Description |
|---|---|---|---|
defs |
map of StyleDef | {} |
Style definitions, by style id |
compositions |
map of StyleComposition | {} |
Compositions, by style id (below) |
conditionals |
array of ConditionalStyle | [] |
Styles for the rows a selector matches (below) |
A style id is a key of defs or compositions.
Style Definition Fields
All fields are optional; specify only what you need. Keyword fields accept the values listed in Keyword values, lengths the forms in Lengths and colors those in Colors; anything else fails validation.
| Field | Type | Default | Description |
|---|---|---|---|
font_family |
string? | null |
CSS font list ("Georgia, serif") |
font_size |
length? | null |
A length or a CSS size keyword (small, larger, …) |
font_weight |
keyword or number? | null |
"normal", "bold", "bolder", "lighter", or 1–1000 (string or number) |
font_style |
keyword? | null |
"normal", "italic", "oblique" |
color |
color? | null |
Text color |
background_color |
color? | null |
Background color |
text_align |
keyword? | null |
"left", "center", "right", "justify", "char" |
vertical_align |
keyword? | null |
"top", "middle", "bottom", "baseline", "super", "sub" |
text_transform |
keyword? | null |
"none", "uppercase", "lowercase", "capitalize" |
text_decoration |
keyword? | null |
"none", "underline", "overline", "line-through" |
white_space |
keyword? | null |
"normal", "nowrap", "pre", "pre-wrap", "pre-line", "break-spaces" |
padding |
Padding? | null |
Space inside the cell, by side (below) |
border |
BorderSet? | null |
The cell’s borders, by side (below) |
indent |
length? | null |
Indent of the first line (may be negative) |
word_break |
keyword? | null |
"normal", "break-all", "keep-all", "break-word" |
overflow |
keyword? | null |
"visible", "hidden", "clip", "scroll", "auto" |
text_overflow |
keyword? | null |
"clip", "ellipsis" |
min_width |
length? | null |
The least the cell is wide |
max_width |
length? | null |
The most the cell is wide |
What each format does with each property is in the Feature Matrix.
Outside HTML, "baseline", "super" and "sub" place a cell’s content at the top: in a table cell they line up the first lines of a row’s cells, which is where top alignment puts them when the cells share a font size. LaTeX output doesn’t write vertical_align (see the Feature Matrix).
How formats other than HTML write font_family and text_transform is described in Output Formats.
Padding
| Field | Type | Default | Description |
|---|---|---|---|
top |
length? | null |
Padding above the content |
right |
length? | null |
Padding to its right |
bottom |
length? | null |
Padding below it |
left |
length? | null |
Padding to its left |
Borders
| Field | Type | Default | Description |
|---|---|---|---|
top |
Border? | null |
The top border |
right |
Border? | null |
The right border |
bottom |
Border? | null |
The bottom border |
left |
Border? | null |
The left border |
Each side is a border:
| Field | Type | Default | Description |
|---|---|---|---|
width |
length? | null |
Border width ("1px") |
style |
keyword? | null |
"none", "hidden", "solid", "dashed", "dotted", "double" |
color |
color? | null |
Border color |
Example
{
"styles": {
"defs": {
"header_bold": {
"font_weight": "bold",
"background_color": "#f0f0f0",
"border": {
"bottom": { "width": "2px", "style": "solid", "color": "#333333" }
}
},
"numeric": {
"font_family": "Courier New, monospace",
"text_align": "right"
}
},
"compositions": {
"header_numeric": {
"extends": "header_bold",
"overrides": { "text_align": "right" }
}
},
"conditionals": [{
"id": "stripe",
"selector": { "row_parity": "even", "scope": "tbody" },
"style": { "background_color": "#FAFAFA" }
}]
}
}How Styles Combine
Every writer resolves a cell’s style the same way (in gridwell-layout). The layers, lowest to highest priority:
- the column’s default style (
column_spec[].style_id), for body and summary cells (column labels are styled by their own row and cell styles); - row striping (
config.row_striping, see Config); - each matching conditional style, in the order listed (later ones win);
- the row’s style (
row.style_id); - the cell’s style (
cell.style_id).
A layer overrides only the properties it sets; everything else shows through from the layers below. padding and border merge side by side, so a cell style that sets only border.bottom keeps a row style’s border.top. A border edge whose style is none or hidden removes that edge. Values that don’t parse (and keywords outside their allowed set) are ignored, so they never reach any output.
A style id is a non-empty name of ASCII letters, digits, _ and - (anything else fails validation with INVALID_STYLE_ID): writers put ids into markup, such as HTML class names. A style id can name a definition or a composition, but not both (DUPLICATE_ID).
Compositions
A composition is its extends definition with overrides laid over it; compositions don’t chain.
| Field | Type | Default | Description |
|---|---|---|---|
extends |
string | required | The id of the definition (in defs, not a composition) it starts from (STYLE_REFS_VALID otherwise) |
overrides |
StyleDef | {} |
The properties it sets in place of the definition’s |
Conditional styles
| Field | Type | Default | Description |
|---|---|---|---|
id |
string | required | The conditional style’s id |
selector |
ConditionalSelector | required | The rows it applies to ({} for every row) |
style |
StyleDef | required | The properties it sets on their cells |
| Field | Type | Default | Description |
|---|---|---|---|
row_parity |
keyword? | null |
"odd" or "even": every other row (below) |
scope |
keyword? | null |
"tbody", "thead" or "table": the rows it applies to |
Conditional selectors
| Selector field | Values | Matches |
|---|---|---|
scope |
tbody (body) |
data rows of every group (not summary rows) |
thead (head) |
column-label rows | |
table (all), or absent |
every row | |
row_parity |
odd, even |
rows numbered from 1, as in CSS :nth-child(odd): data rows count across all groups, head rows within the head, summary rows within their group |
| absent | every row in scope |
An unknown value is an UNKNOWN_VALUE error, except in a table of a newer minor version, where the style applies to no row (warned for). So does a selector with a field this gridwell doesn’t know, in a table of any version: a newer version may narrow selectors with new fields, and a style that matched more rows than meant would be worse than none. It is warned for as IGNORED_SELECTOR.
Color Values
- Named: all 148 CSS named colors (
red,steelblue,rebeccapurple, …) - Hex:
#RGB,#RGBA,#RRGGBB,#RRGGBBAA - Functional:
rgb()/rgba()andhsl()/hsla(), in comma syntax (rgb(255, 0, 0)) or space syntax with optional alpha (rgb(255 0 0 / 50%)) - Keyword:
transparent
Anything else fails validation with INVALID_COLOR; see Validation for details and for the length forms each field accepts.