File: offset.md

package info (click to toggle)
textual 2.1.2-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 55,080 kB
  • sloc: python: 85,423; lisp: 1,669; makefile: 101
file content (63 lines) | stat: -rw-r--r-- 1,541 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Offset

The `offset` style defines an offset for the position of the widget.

## Syntax

--8<-- "docs/snippets/syntax_block_start.md"
offset: <a href="../../css_types/scalar">&lt;scalar&gt;</a> <a href="../../css_types/scalar">&lt;scalar&gt;</a>;

offset-x: <a href="../../css_types/scalar">&lt;scalar&gt;</a>;
offset-y: <a href="../../css_types/scalar">&lt;scalar&gt;</a>
--8<-- "docs/snippets/syntax_block_end.md"

The two [`<scalar>`](../css_types/scalar.md) in the `offset` define, respectively, the offsets in the horizontal and vertical axes for the widget.

To specify an offset along a single axis, you can use `offset-x` and `offset-y`.

## Example

In this example, we have 3 widgets with differing offsets.

=== "Output"

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

=== "offset.py"

    ```python
    --8<-- "docs/examples/styles/offset.py"
    ```

=== "offset.tcss"

    ```css hl_lines="13 20 27"
    --8<-- "docs/examples/styles/offset.tcss"
    ```

## CSS

```css
/* Move the widget 8 cells in the x direction and 2 in the y direction */
offset: 8 2;

/* Move the widget 4 cells in the x direction
offset-x: 4;
/* Move the widget -3 cells in the y direction
offset-y: -3;
```

## Python

You cannot change programmatically the offset for a single axis.
You have to set the two axes at the same time.

```python
# Move the widget 2 cells in the x direction, and 4 in the y direction.
widget.styles.offset = (2, 4)
```

## See also

 - The [layout guide](../guide/layout.md#offsets) section on offsets.