Skip to contents

The margin_*() functions adjust a tag element's margin, the space outside and around the element, its border, and its content.

Usage

margin_all(x, ...)

margin_top(x, ...)

margin_right(x, ...)

margin_bottom(x, ...)

margin_left(x, ...)

margin_horizontal(x, ...)

margin_vertical(x, ...)

Arguments

x

A tag element or .style pronoun.

...

A number or character string specifying a margin. One or more of,

  • "-5"

  • "-4"

  • "-3"

  • "-2"

  • "-1"

  • 0

  • 1

  • 2

  • 3

  • 4

  • 5

  • "auto"

    Use name-value pairs to specify breakpoints.

Value

An object of the same type as x.

See also

gap_all() for flex spacing.

Examples


library(htmltools)

div(
  .style %>%
    margin_left(3) %>%
    margin_right(3),
  "Left margin, right margin"
)
#> <div class="ms-3 me-3">Left margin, right margin</div>

div(
  .style %>%
    margin_horizontal(3),
  "Shorthand for left and right margins"
)
#> <div class="mx-3">Shorthand for left and right margins</div>

div(
  .style %>%
    margin_horizontal("auto"),
  "A centered element."
)
#> <div class="mx-auto">A centered element.</div>