Angular Material 教程之布局篇 (二) : 布局容器

布局容器

布局和容器

使用容器元素上的layout指令来为其子元素指定布局方向:水平排列(layout="row")或垂直排列(layout="column")。

请注意,如果指定的layout指令没有值,那么row是默认的布局方向。

  • row: 水平排列的项目。 max-height = 100%max-width 是容器中项目的宽度。

  • column: 垂直排列的项目。 max-width = 100%max-height 是容器中项目的高度。

《Angular Material 教程之布局篇 (二) : 布局容器》

<!-- 水平布局 -->
<div layout="row">
  <div flex>First item in row</div>
  <div flex>Second item in row</div>
</div>

<!-- 垂直布局 -->
<div layout="column">
  <div flex>First item in column</div>
  <div flex>Second item in column</div>
</div>

请注意,layout仅影响该容器的直接子元素的流向。

布局和响应断点

如布局简介中所介绍的,您可以使用断点 别名后缀 根据设备视图大小更改布局。

要使布局根据设备屏幕大小自动更改,请使用以下layout API之一为具有视图宽度的设备设置布局方向:

layout APIflex API激活设备时
layoutflex设置默认布局方向,除非被另一个断点覆盖。
layout-xsflex-xswidth < 600px
layout-gt-xsflex-gt-xswidth >= 600px
layout-smflex-sm600px <= width < 960px
layout-gt-smflex-gt-smwidth >= 960px
layout-mdflex-md960px <= width < 1280px
layout-gt-mdflex-gt-mdwidth >= 1280px
layout-lgflex-lg1280px <= width < 1920px
layout-gt-lgflex-gt-lgwidth >= 1920/b>px
layout-xlflex-xlwidth >= 1920px

《Angular Material 教程之布局篇 (二) : 布局容器》

对于下面的代码,当缩小浏览器窗口宽度时,注意流动方向更改为移动设备(xs)的column。 当您展开时,它将重置为gt-sm视图大小的row

《Angular Material 教程之布局篇 (二) : 布局容器》

<div layout="row" layout-xs="column">
  <div flex>
    I'm above on mobile, and to the left on larger devices.
  </div>
  <div flex>
    I'm below on mobile, and to the right on larger devices.
  </div>
</div>

有关更多选项(如填充,对齐等),请参阅“布局参数”章节。

    原文作者:DemoPark
    原文地址: https://segmentfault.com/a/1190000007217054
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞