Skip to content

Margin

Margin #

Margin class has the properties to set margins for all sides of the rectangle.

bottom #

bottom: Number = 0

The margin applied to the bottom.

left #

left: Number = 0

The margin applied to the left.

right #

right: Number = 0

The margin applied to the right.

top #

top: Number = 0

The margin applied to the top.

all #

all(value: Number) -> Margin

Applies the same margin to all sides.

only #

only(
    *,
    left: Number = 0,
    top: Number = 0,
    right: Number = 0,
    bottom: Number = 0,
) -> Margin

Applies margin to the specified sides.

symmetric #

symmetric(
    *, vertical: Number = 0, horizontal: Number = 0
) -> Margin

Applies vertical margin to top and bottom sides and horizontal margin to left and right sides.

Examples#

Example 1#

import flet as ft


def main(page: ft.Page):
    page.title = "Margin Example"

    page.add(
        ft.Row(
            spacing=0,
            controls=[
                ft.Container(
                    content=ft.ElevatedButton("container_1"),
                    bgcolor=ft.Colors.AMBER,
                    # padding=ft.Padding.all(10),
                    margin=ft.Margin.all(10),
                    width=200,
                    height=200,
                ),
                ft.Container(
                    content=ft.ElevatedButton("container_2"),
                    bgcolor=ft.Colors.AMBER,
                    # padding=ft.Padding.all(20),
                    margin=ft.Margin.all(20),
                    width=200,
                    height=200,
                ),
                ft.Container(
                    content=ft.ElevatedButton("container_3"),
                    bgcolor=ft.Colors.AMBER,
                    # padding=ft.Padding.symmetric(horizontal=10),
                    margin=ft.Margin.symmetric(vertical=10),
                    width=200,
                    height=200,
                ),
                ft.Container(
                    content=ft.ElevatedButton("container_4"),
                    bgcolor=ft.Colors.AMBER,
                    # padding=ft.Padding.only(left=10),
                    margin=ft.Margin.only(left=10),
                    width=200,
                    height=200,
                ),
            ],
        )
    )


ft.run(main)