--- title: Flexbox layout with iron-flex-layout summary: "Simple flexbox layout" tags: ['beginner'] elements: ['iron-flex-layout'] updated: 2015-05-03 --- ## Overview The `iron-flex-layout` component provides simple ways to use [CSS flexible box layout](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Flexible_boxes), also known as _flexbox_. This component provides two different ways to use flexbox: * Layout classes. The layout class stylesheet provides a simple set of class-based flexbox rules. Layout classes let you specify layout properties directly in markup. * Custom CSS mixins. The mixin stylesheet includes custom CSS mixins that can be applied inside a CSS rule using the `@apply` function. Using the classes or CSS mixins is largely a matter of preference. The following sections discuss how to use the each of the stylesheets. ### Using layout classes To use layout classes import the `classes/iron-flex-layout` file. Then simply apply the classes to any element.
Many of the layout rules involve combinations of multiple classes (such as `layout horizontal wrap` above). The order in which the classes are specified doesn't matter, so `layout horizontal` and `horizontal layout` are equivalent. _Currently_, the layout class stylesheet uses the `/deep/` combinator and therefore, works across all local DOM boundaries. Because `/deep/` is slated to be removed from the shadow DOM spec, this stylesheet will eventually be replaced by a set of rules that do not use `/deep/`. When that happens, the stylesheet will need to be imported into each scope where it's used. ### Using layout mixins Custom mixins can be applied inside a Polymer custom element's stylesheet, **or** inside a `custom-style` stylesheet to apply styles to the main document. (They cannot be applied in the main document without a `custom-style` stylesheet.) **Example: using mixins in the main document** ... ...
One
Two
Three
**Example: using mixins in a Polymer element** ... In general the mixins require a little more code to use, but they can be preferable if you don't want to use the classes, or if you want to switch layouts based on a media query. Custom CSS properties and mixins are features provided by the Polymer library. See [Cross-scope styling](https://www.polymer-project.org/1.0/docs/devguide/styling.html#xscope-styling) in the Polymer developer guide. ## Horizontal and vertical layout Create a flex container that lays out its children vertically or horizontally. Class | Mixin | Result :-|:-|:- layout horizontal| ‑‑layout-horizontal | Horizontal layout container. layout vertical | ‑‑layout-verical | Vertical layout container. **Example: classes**
One
Two
Three
**Example: mixins**