Files
textual/docs/styles/grid/grid_gutter.md
Rodrigo Girão Serrão 196d430582 Style all Textual CSS as 'sass'
Textual CSS is better highlighted in SASS code blocks because the SASS parser seems to be more lenient.
2023-01-09 11:20:04 +00:00

1.9 KiB

Grid-gutter

The grid-gutter style sets the size of the gutter in the grid layout. That is, it sets the space between adjacent cells in the grid.

Gutter is only applied between the edges of cells. No spacing is added between the edges of cells and the edges of the container.

!!! note

This style only affects widgets with `layout: grid`.

Syntax

--8<-- "docs/snippets/syntax_block_start.md" grid-gutter: <scalar> [<scalar>]; --8<-- "docs/snippets/syntax_block_end.md"

The style grid-gutter takes one or two <scalar> that set the length of the gutter along the vertical and horizontal axes. If only one <scalar> is supplied, it sets the vertical and horizontal gutters. If two are supplied, they set the vertical and horizontal gutters, respectively.

Values

--8<-- "docs/snippets/type_syntax/scalar.md"

Example

The example below employs a common trick to apply visually consistent spacing around all grid cells.

=== "Output"

```{.textual path="docs/examples/styles/grid_gutter.py"}
```

=== "grid_gutter.py"

```py
--8<-- "docs/examples/styles/grid_gutter.py"
```

=== "grid_gutter.css"

```sass
--8<-- "docs/examples/styles/grid_gutter.css"
```

1. We set the horizontal gutter to be double the vertical gutter because terminal cells are typically two times taller than they are wide. Thus, the result shows visually consistent spacing around grid cells.

CSS

/* Set vertical and horizontal gutters to be the same */
grid-gutter: 5%;

/* Set vertical and horizontal gutters separately */
grid-gutter: 1 2;

Python

Vertical and horizontal gutters correspond to different Python properties, so they must be set separately:

widget.styles.grid_gutter_vertical = "1"
widget.styles.grid_gutter_horizontal = "2"