# NOT RUN {
### Different `direction`s
# Many of `flex()`'s arguments are viewport responsive and below we will see
# how useful this can be. On small screens the flex items are placed
# vertically and can occupy the full width of the mobile device. On medium
# or larger screens the items are placed horizontally once again.
div(
div("A flex item") %>%
padding(3) %>%
border(),
div("A flex item") %>%
padding(3) %>%
border(),
div("A flex item") %>%
padding(3) %>%
border()
) %>%
display("flex") %>%
flex(
direction = list(xs = "column", md = "row") # <-
) %>%
background("grey") %>%
border()
# *Resize the browser for this example.*
# You can keep items as a column by specifying only `"column"`.
div(
div("A flex item") %>%
padding(3) %>%
border(),
div("A flex item") %>%
padding(3) %>%
border(),
div("A flex item") %>%
padding(3) %>%
border()
) %>%
display("flex") %>%
flex(direction = "column") # <-
### Spacing items with `justify`
# Below is a series of examples showing how to change the horizontal
# alignment of your flex items. Let's start by pushing items to the
# beginning of their parent container.
div(
replicate(
div("A flex item") %>%
padding(3) %>%
border(),
n = 5,
simplify = FALSE
)
) %>%
display("flex") %>%
flex(justify = "start") # <-
# We can also push items to the **end**.
div(
replicate(
div("A flex item") %>%
padding(3) %>%
border(),
n = 5,
simplify = FALSE
)
) %>%
display("flex") %>%
flex(justify = "end") # <-
# Without using a table layout we can **center** items.
div(
replicate(
div("A flex item") %>%
padding(3) %>%
border(),
n = 5,
simplify = FALSE
)
) %>%
display("flex") %>%
flex(justify = "center") # <-
# You can also put space **between** items
div(
replicate(
div("A flex item") %>%
padding(3) %>%
border(),
n = 5,
simplify = FALSE
)
) %>%
display("flex") %>%
flex(justify = "between") # <-
# ... or put space **around** items.
div(
replicate(
div("A flex item") %>%
padding(3) %>%
border(),
n = 5,
simplify = FALSE
)
) %>%
display("flex") %>%
flex(justify = "around") # <-
# *The "between" and "around" values come from the original CSS values
# "space-between" and "space-around".*
### Wrap onto new lines
# Using flexbox we can also control how items wrap onto new lines.
div(
replicate(
div("A flex item") %>%
padding(3) %>%
border(),
n = 5,
simplify = FALSE
)
) %>%
display("flex") %>%
flex(wrap = TRUE)
# }
Run the code above in your browser using DataLab