Skip to content

Offset

The offset rule adds an offset to the widget's position. The offset is given as two values.

Coordinates may be specified individually with offset-x and offset-y.

Syntax

offset: <SCALAR> <SCALAR>;

Example

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

from textual.app import App
from textual.widgets import Static


class OffsetApp(App):
    def compose(self):
        yield Static("Paul (offset 8 2)", classes="paul")
        yield Static("Duncan (offset 4 10)", classes="duncan")
        yield Static("Chani (offset 0 5)", classes="chani")


app = OffsetApp(css_path="offset.css")
Screen {
    background: white;
    color: black;
    layout: horizontal;
}
Static {             
    width: 20;
    height: 10;
    content-align: center middle; 
}

.paul {
    offset: 8 2;
    background: red 20%;
    border: outer red;
    color: red;
}

.duncan {
    offset: 4 10;
    background: green 20%;
    border: outer green;
    color: green;
}

.chani {
    offset: 0 5;
    background: blue 20%;
    border: outer blue;
    color: blue;
}

OffsetApp ▛▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▜ ▛▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▜ Paul (offset 8 2) Chani (offset 0 5)▐ ▛▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▙▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ Duncan (offset ▙▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▟ 10) ▙▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▟

CSS

/* Move the widget 2 cells in the x direction, and 4 in the y direction. */
offset: 2 4;

Python

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