Skip to content

Commit 85b1d0c

Browse files
authored
Merge pull request #1418 from davep/faq-middle-of-screen
Add a FAQ about aligning things in the middle of a container
2 parents dd2b89b + 94a2175 commit 85b1d0c

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: "How do I center a widget in a screen?"
3+
alt_titles:
4+
- "centre a widget"
5+
- "center a control"
6+
- "centre a control"
7+
---
8+
9+
To center a widget within a container use
10+
[`align`](https://textual.textualize.io/styles/align/). But remember that
11+
`align` works on the *children* of a container, it isn't something you use
12+
on the child you want centered.
13+
14+
For example, here's an app that shows a `Button` in the middle of a
15+
`Screen`:
16+
17+
```python
18+
from textual.app import App, ComposeResult
19+
from textual.widgets import Button
20+
21+
class ButtonApp(App):
22+
23+
CSS = """
24+
Screen {
25+
align: center middle;
26+
}
27+
"""
28+
29+
def compose(self) -> ComposeResult:
30+
yield Button("PUSH ME!")
31+
32+
if __name__ == "__main__":
33+
ButtonApp().run()
34+
```

0 commit comments

Comments
 (0)