angular4 Flex Layout开发实践

本文介绍了如何使用 @angular/flex-layout 插件进行Angular应用的Flex布局开发,包括fxLayout、fxLayoutAlign、fxLayoutGap、fxFlex、fxFlexOrder、fxFlexOffset和fxHide/fxShow等属性的使用方法,提供了丰富的布局示例,帮助开发者实现灵活的响应式布局。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

angular flex

@angular/flex-layout angular辅助flex布局的插件。
插件地址:https://github.com/angular/flex-layout

演示样本

这里写图片描述

<div class="container"
     fxLayout="row"
     fxLayout.xs="column"
     fxLayoutAlign="center"
     fxLayoutGap="10px"
     fxLayoutGap.xs="0">
  <div class="item item-1" fxFlex="33">Item 1</div>
  <div class="item item-2" fxFlex="33">Item 2</div>
  <div class="item item-3" fxFlex="33">Item 3</div>
</div>

fxLayout

可选参数 row | column | row-reverse | column-reverse | wrap
row 为横向布局,column为纵向布局。wrap为当三个item大于一行时,是选择继续在行内自适应,还是另起一行。

breakpointmediaQuery
xs‘screen and (max-width: 599px)’
sm‘screen and (min-width: 600px) and (max-width: 959px)’
md‘screen and (min-width: 960px) and (max-width: 1279px)’
lg‘screen and (min-width: 1280px) and (max-width: 1919px)’
xl‘screen and (min-width: 1920px) and (max-width: 5000px)’
lt-sm‘screen and (max-width: 599px)’
lt-md‘screen and (max-width: 959px)’
lt-lg‘screen and (max-width: 1279px)’
lt-xl‘screen and (max-width: 1919px)’
gt-xs‘screen and (min-width: 600px)’
gt-sm‘screen and (min-width: 960px)’
gt-md‘screen and (min-width: 1280px)’
gt-lg‘screen and (min-width: 1920px)’

当屏幕小于599px时,样例为
这里写图片描述

fxLayoutAlign

布局参考线,当item大于一行时,并且fxLayout设置wrap可以看出来,例如

<div class="container"
     fxLayout="row wrap"
     fxLayout.xs="column"
     fxLayoutAlign="center"
     fxLayoutGap="10px"
     fxLayoutGap.xs="0">
  <div class="item item-1" fxFlex="55">Item 1</div>
  <div class="item item-2" fxFlex="20">Item 2</div>
  <div class="item item-3" fxFlex="33">Item 3</div>
</div>

这里写图片描述

居中布局,也可以靠左靠右。

fxLayoutGap

布局间隙,每个色块之间的间距值。

fxFlex

弹性盒子的宽度值,默认单位为百分比。

fxFlexOrder

定义排序,值越小排序越靠前

<div class="container"
     fxLayout="row "
     fxLayout.xs="column"
     fxLayoutAlign="start"
     fxLayoutGap="10px"
     fxLayoutGap.xs="0">
  <div class="item item-1" fxFlex="33" fxFlexOrder="2">Item 1</div>
  <div class="item item-2" fxFlex="33" fxFlexOrder="1">Item 2</div>
  <div class="item item-3" fxFlex="33">Item 3</div>
</div>

这里写图片描述

fxFlexOffset

偏移,设置fxLayoutGap时,失效。

fxHide/fxShow

控制dom显示隐藏。

<div class="container"
     fxLayout="row "
     fxLayout.xs="column"
     fxLayoutGap="0">
  <div class="item item-1" fxFlex="33" fxHide="{{hide}}" fxFlexOffset="15">
    <div>item1</div>
  </div>
  <div class="item item-2" (click)="onSave()" fxFlex="33">Item 2</div>
  <div class="item item-3" fxFlex="33" >Item 3</div>
</div>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值