angular - 如何使用角度弹性布局居中对齐项目
问题描述
我正在尝试使用https://tburleson-layouts-demos.firebaseapp.com/#/docs中提到的 angular flex 布局构建 angular material 应用程序,我尝试了各种组合,但没有任何东西对我有用。我正在尝试在工具栏下构建几张卡片,它们应该占据大约 70% 的区域,居中对齐,但它们最终使用了所有空间。我的html是
<!--The content below is only a placeholder and can be replaced.-->
<div fxLayout="column" fxLayoutAlign="space-around center" fxLayoutGap="20px">
<div fxLayout="row">
<mat-toolbar color="primary">
<span>Flex layout Example</span>
</mat-toolbar>
</div>
<div fxLayout="row" fxFlex="66">
<mat-card>
<mat-card-header>Sample Card</mat-card-header>
</mat-card>
</div>
</div>
如果我在 css 类中添加 width:66% 它可以工作,但为什么我不能只使用 fxFlex 呢?
按照manu的建议。
<!--The content below is only a placeholder and can be replaced.-->
<div fxLayout="column" fxLayoutAlign="space-around center" fxLayoutGap="20px">
<div fxLayout="row">
<mat-toolbar color="primary">
<span>Flex layout Example</span>
</mat-toolbar>
</div>
<div fxLayout="row" fxFlex="66%" fxLayoutAlign="center center">
<mat-card>
<mat-card-header>Sample Card</mat-card-header>
</mat-card>
</div>
</div>
也没有工作
解决方案
您错过了 fxFlex="66%" 中的 % 以及居中对齐添加 fxLayoutAlign="center center"。fxLayoutAlign 中的第一个参数用于主轴,第二个参数用于交叉轴。
推荐阅读
- angular - Angular Firebase 2 - 从数据库中读取数据一次
- spreadsheet - 使用 Python 2.65 写入电子表格
- apache - Apache 服务器未在 Xampp 便携版上启动
- php - 迭代数据并将csv文件放入php中的问题
- go - 获取调用函数的名称和包
- twilio - 如何在客户端之间转移 twilio 入站呼叫
- javascript - jQuery 不正确的数组处理:长度 = 0 错误?
- node.js - 服务器端 (Node.js) 和客户端 (Angular) 上的 Socket.io 路径
- php - PHP - 为值会话设置键的多个维度的方法
- angular - 基于类的 Scss 变量