mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Complete reference for content-align.
This commit is contained in:
@@ -1,13 +1,18 @@
|
||||
# Content-align
|
||||
|
||||
The `content-align` style aligns content _inside_ a widget.
|
||||
Not to be confused with [`align`](../align).
|
||||
|
||||
You can specify the alignment of content on both the horizontal and vertical axes at the same time,
|
||||
or on each of the axis separately.
|
||||
|
||||
You can specify the alignment of content on both the horizontal and vertical axes.
|
||||
|
||||
## Syntax
|
||||
|
||||
```
|
||||
content-align: <HORIZONTAL> <VERTICAL>;
|
||||
content-align-horizontal: <HORIZONTAL>;
|
||||
content-align-vertical: <VERTICAL>;
|
||||
```
|
||||
|
||||
### Values
|
||||
@@ -28,7 +33,9 @@ content-align: <HORIZONTAL> <VERTICAL>;
|
||||
| `middle` | Align content in the middle of the vertical axis |
|
||||
| `bottom` | Align content at the bottom of the vertical axis |
|
||||
|
||||
## Example
|
||||
## Examples
|
||||
|
||||
This first example shows three labels stacked vertically, each with different content alignments.
|
||||
|
||||
=== "content_align.py"
|
||||
|
||||
@@ -38,7 +45,7 @@ content-align: <HORIZONTAL> <VERTICAL>;
|
||||
|
||||
=== "content_align.css"
|
||||
|
||||
```scss
|
||||
```scss hl_lines="2 7-8 13"
|
||||
--8<-- "docs/examples/styles/content_align.css"
|
||||
```
|
||||
|
||||
@@ -47,6 +54,26 @@ content-align: <HORIZONTAL> <VERTICAL>;
|
||||
```{.textual path="docs/examples/styles/content_align.py"}
|
||||
```
|
||||
|
||||
The next example shows a 3 by 3 grid of labels.
|
||||
Each label has its text aligned differently.
|
||||
|
||||
=== "content_align_all.py"
|
||||
|
||||
```py
|
||||
--8<-- "docs/examples/styles/content_align_all.py"
|
||||
```
|
||||
|
||||
=== "content_align_all.css"
|
||||
|
||||
```css
|
||||
--8<-- "docs/examples/styles/content_align_all.css"
|
||||
```
|
||||
|
||||
=== "Output"
|
||||
|
||||
```{.textual path="docs/examples/styles/content_align_all.py"}
|
||||
```
|
||||
|
||||
## CSS
|
||||
|
||||
```sass
|
||||
@@ -54,6 +81,11 @@ content-align: <HORIZONTAL> <VERTICAL>;
|
||||
content-align: center middle;
|
||||
/* Align content at the top right of a widget */
|
||||
content-align: right top;
|
||||
|
||||
/* Change the horizontal alignment of the content of a widget */
|
||||
content-align-horizontal: right;
|
||||
/* Change the vertical alignment of the content of a widget */
|
||||
content-align-vertical: middle;
|
||||
```
|
||||
|
||||
## Python
|
||||
@@ -62,4 +94,9 @@ content-align: right top;
|
||||
widget.styles.content_align = ("center", "middle")
|
||||
# Align content at the top right of a widget
|
||||
widget.styles.content_align = ("right", "top")
|
||||
|
||||
# Change the horizontal alignment of the content of a widget
|
||||
widget.styles.content_align_horizontal = "right"
|
||||
# Change the vertical alignment of the content of a widget
|
||||
widget.styles.content_align_vertical = "middle"
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user