Flex provides a layout API for using Flexbox CSS.
Demo https://tptshepo.github.io/elm-flex-layout
fxLayout : Direction -> Alignment -> Alignment -> List (Html.Attribute msg)
Returns an array of Html.Attributes.style
required to align the child items.
Usage
fxLayout Direction Alignment Alignment
Example
div ([] ++ fxLayout Flex.row Flex.spaceAround Flex.center)
[ div [] [ text "1" ]
, div [] [ text "2" ]
, div [] [ text "3" ]
, div [] [ text "4" ]
, div [] [ text "5" ]
]
fxRow : Alignment -> Alignment -> List (Html.Attribute msg)
Shorthad for fxLayout Flex.row
.
Example
div ([] ++ fxRow Flex.spaceAround Flex.center)
[ div [] [ text "1" ]
, div [] [ text "2" ]
, div [] [ text "3" ]
, div [] [ text "4" ]
, div [] [ text "5" ]
]
fxColumn : Alignment -> Alignment -> List (Html.Attribute msg)
Shorthad for fxLayout Flex.column
.
Example
div ([] ++ fxColumn Flex.spaceAround Flex.center)
[ div [] [ text "1" ]
, div [] [ text "2" ]
, div [] [ text "3" ]
, div [] [ text "4" ]
, div [] [ text "5" ]
]
alignmentToString : Alignment -> String
Return a string version of the Alignment
type
This establishes the main-axis, thus defining the direction flex items are placed in the flex container.
row : Direction
row
: This establishes the main-axis, thus defining the direction flex items are placed in the flex container.
column : Direction
column
: Same as row but top to bottom
This defines the alignment along the main axis. It helps distribute extra free space leftover when either all the flex items on a line are inflexible, or are flexible but have reached their maximum size. It also exerts some control over the alignment of items when they overflow the line.
start : Alignment
flex-start
items are placed at the start of the cross axis. The difference between these is subtle, and is about respecting the flex-direction rules.
end : Alignment
flex-end
items are placed at the end of the cross axis. The difference again is subtle and is about respecting flex-direction rules.
center : Alignment
center
items are centered in the cross-axis.
stretch : Alignment
stretch
to fill the container (still respect min-width/max-width)
spaceBetween : Alignment
space-between
items are evenly distributed in the line; first item is on the start line, last item on the end line.
spaceAround : Alignment
space-around
items are evenly distributed in the line with equal space around them. Note that visually the spaces aren’t equal, since all the items have equal space on both sides. The first item will have one unit of space against the container edge, but two units of space between the next item because that next item has its own spacing that applies.
spaceEvenly : Alignment
space-evenly
items are distributed so that the spacing between any two items (and the space to the edges) is equal.