File size: 1,371 Bytes
5b76e0f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Margin

The `margin` rule adds space around the entire widget. Margin may be specified with 1, 2 or 4 values.

| Example            | Description                                                         |
|--------------------|---------------------------------------------------------------------|
| `margin: 1;`       | A single value sets a margin of 1 around all 4 edges                |
| `margin: 1 2;`     | Two values sets the margin for the top/bottom and left/right edges  |
| `margin: 1 2 3 4;` | Four values sets top, right, bottom, and left margins independently |

Margin may also be set individually by setting `margin-top`, `margin-right`, `margin-bottom`, or `margin-left` to a single value.

## Syntax

```
margin: <INTEGER>;
margin: <INTEGER> <INTEGER>;
margin: <INTEGER> <INTEGER> <INTEGER> <INTEGER>;
```

## Example

In this example we add a large margin to some static text.

=== "margin.py"

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

=== "margin.css"

    ```css
    --8<-- "docs/examples/styles/margin.css"
    ```

=== "Output"

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

## CSS

```sass
/* Set margin of 2 on the top and bottom edges, and 4 on the left and right */
margin: 2 4;
```

## Python

```python
# In Python you can set the margin as a tuple of integers
widget.styles.margin = (2, 3)
```