1-4-1 Flexbox layout with iron-flex-layout 使用Flexbox布局

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, also known as flexbox. This component provides two different ways to use flexbox:
iron-flex-layout组件提供简单的方法去使用CSS flexible box 布局,也被称为flexbox。这个组件提供两种不同的方法来使用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.
  • 布局类。布局类的样式表提供了一组简单的基于类的flexbox规则。布局类可以让你直接在标记指定布局属性。
  • Custom CSS mixins. The mixin stylesheet includes custom CSS mixins that can be applied inside a CSS rule using the @apply function.
  • 自定义CSS混入。该混入样式表包括了可以使用@apply功能的CSS规则内应用自定义CSS混入。
    Using the classes or CSS mixins is largely a matter of preference. The following sections discuss how to use the each of the stylesheets.
    使用的类或CSS混入在很大程度上是偏好的问题。以下各节讨论如何使用每个样式表。
    Note: Before using either of these stylesheets, it's helpful to be familiar with the basics of flexbox layout. Chris Coyier's A Complete Guide to Flexbox is a good primer.
    注: 使用其中任何一个样式表之前,它有助于熟悉的flexbox布局的基本知识。Chris Coyier的一个完整的指南Flexbox是一个很好的引子。

Using layout classes

使用布局类

To use layout classes import the classes/iron-flex-layout file.
要使用布局类导入classes/iron-flex-layout文件。


Then simply apply the classes to any element.
然后简单地套用类的任何元素。

Many of the layout rules involve combinations of multiple classes (such as layout horizontal wrap above).
许多布局规则涉及多个类的组合(如layout horizontal wrap以上)。
The order in which the classes are specified doesn't matter, so layout horizontal and horizontal layout are equivalent.
其中类指定无所谓的顺序,所以layout horizontalhorizontal layout是等价的。
Currently, the layout class stylesheet uses the /deep/ combinator and therefore, works across all local DOM boundaries.

目前,该布局类样式表使用了/deep/组合子,因此,可以跨所有本地DOM边界。
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.
由于/deep/被提名从阴影DOM规范中删除,这个样式表将最终由一组规则所取代不使用/deep/。当发生这种情况,样式表将需要导入的地方使用它的每个范围。

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.)
自定义混入可以被应用于Polymer自定义标签的样式表内,一个custom-style样式表样式应用到主文档中。 (没有'custom-style`样式表时他们不能在主文档中应用。)
Example: using mixins in the main document
例:在主文档中使用混入



  ...

  

  ...

  
  
  




  
One
Two
Three

Example: using mixins in a Polymer element
例:在Polymer标签中使用混入



  ...



  
  
  

  

  


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
in the Polymer developer guide.
自定义CSS属性和混入是由Polymer库提供的功能。参见Polymer开发指南中的跨范围样式。

Horizontal and vertical layout

水平和垂直布局

Create a flex container that lays out its children vertically or horizontally.
创建Flex容器将其子内容垂直或水平分布。

Class Mixin Result
layout horizontal ‑‑layout-horizontal Horizontal layout container.
layout vertical ‑‑layout-vertical Vertical layout container.
混入 结果
layout horizontal ‑‑layout-horizontal 水平布局容器。
layout vertical ‑‑layout-vertical 垂直布局容器。

Example: classes
例: 类

One
Two
Three

Example: mixins
例: 混合