Description Usage Arguments Centering elements Details Examples
The flex()
function adjusts the flex box layout of an element. To use
the flex box layout the element must also use the flex display, see
display()
. The flex box layout is incredibly powerful and allows centering
of elements vertically or horizontally, automatic adjustment of space between
or around child elements, and more.
Direct child elements of a flex box container are automatically considered
flex items and may be adjusted with item()
.
1 |
x |
A tag element or .style pronoun. |
direction |
A responsive argument. One of If If |
justify |
A responsive argument. One of If |
align |
A responsive argument. One of |
wrap |
A responsive argument. One of |
Center an input above a larger element or next to the element if space allows.
div( .style %>% display("flex") %>% flex(direction = c(default = "column", md = "row")), radioButtons("id", "A sample input", c("Choice 1", "Choice 2")) %>% margin(h = c(xs = "auto", md = 0)), div( .style %>% width(100) %>% background("indigo") %>% text("white"), "Plot placeholder" ) )
Plot placeholder
This section needs pretty specific examples of how to use flex. I don’t know that people will want a tutorial on flex.
For the sake of the demo let’s create a flex item help function.
flexItem <- function(...) { div( .style %>% padding(3) %>% border("blue"), "A flex item", ... ) }
direction
sMany of flex()
’s arguments are viewport responsive. 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.
div( .style %>% display("flex") %>% flex( direction = c(xs = "column", md = "row") # <- ), flexItem(), flexItem(), flexItem() )
A flex item
A flex item
A flex item
Resize the browser for this example.
You can keep items as a column by specifying only "column"
.
div( .style %>% display("flex") %>% flex(direction = "column"), # <- flexItem(), flexItem(), flexItem() )
A flex item
A flex item
A flex item
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( .style %>% display("flex") %>% flex(justify = "start"), # <- flexItem(), flexItem(), flexItem(), flexItem() )
A flex item
A flex item
A flex item
A flex item
We can also push items to the end.
div( .style %>% display("flex") %>% flex(justify = "end"), # <- flexItem(), flexItem(), flexItem(), flexItem() )
A flex item
A flex item
A flex item
A flex item
Without using a table layout we can center items.
div( .style %>% display("flex") %>% flex(justify = "center"), # <- flexItem(), flexItem(), flexItem(), flexItem() )
A flex item
A flex item
A flex item
A flex item
You can also put space between items
div( .style %>% display("flex") %>% flex(justify = "between"), # <- flexItem(), flexItem(), flexItem(), flexItem() )
A flex item
A flex item
A flex item
A flex item
… or put space around items.
div( .style %>% display("flex") %>% flex(justify = "around"), # <- flexItem(), flexItem(), flexItem(), flexItem() )
A flex item
A flex item
A flex item
A flex item
The "between"
and "around"
values come from the original CSS values
"space-between"
and "space-around"
.
wrap
onto new linesUsing flexbox we can also control how items wrap onto new lines.
div( .style %>% display("flex") %>% flex(wrap = TRUE), flexItem(), flexItem(), flexItem(), flexItem() )
A flex item
A flex item
A flex item
A flex item
1 2 3 4 5 6 7 8 9 |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.