margin: Margins

Description Usage Arguments Auto margins Examples

View source: R/margin.R

Description

The margin() function adjusts the outer spacing of a tag element. The margin of a tag element is the space outside and around the tag element, its border, and its content.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
margin(
  x,
  all = NULL,
  top = NULL,
  right = NULL,
  bottom = NULL,
  left = NULL,
  horizontal = NULL,
  vertical = NULL
)

Arguments

x

A tag element or .style pronoun.

all

A responsive argument.

One of -5:5 or "auto" specifying a margin for all sides of the tag element, defaults to NULL, in which case the argument is ignored. 0 removes all outer space, 5 adds the most space, and negative values will consume space and pull the element in that direction.

top, right, bottom, left

A responsive argument.

One of -5:5 or "auto" specifying a margin for the respective side of the tag element.

horizontal

A responsive argument.

One of -5:5 or "auto" specifying a margin for the left and right sides of the tag element.

vertical

A responsive argument.

One of -5:5 or "auto" specifying a margin for the top and bottom sides of the tag element.

Auto margins

In most modern browsers you want to horizontally center a tag element using the flex layout. Alternatively, you can horizontally center an element using margin(.., horizontal = "auto").

div(
  .style %>%
    margin(v = 2, h = "auto") %>%  # <-
    padding(3) %>%
    background("teal"),
  "Nam a sapien. Integer placerat tristique nisl."
)
html_preserve

Nam a sapien. Integer placerat tristique nisl.

/html_preserve

Examples

 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
library(htmltools)

div(
  .style %>%
    margin(left = 3, right = 3),
  "Mauris mollis tincidunt felis."
)

div(
  .style %>%
    margin(horizontal = 3),
  "Nulla posuere."
)


div(
  .style %>%
    margin(l = 2, b = 1),
  "Sed bibendum."
)


div(
  .style %>%
    margin(h = "auto"),
  "Sed id ligula quis est convallis tempor."
)

cascadess documentation built on Jan. 13, 2021, 5:10 p.m.