css - 如何在引导网格中将 *ngFor 生成的内容居中?
问题描述
我想使用 Bootstrap 网格系统将一些内容集中在一行中。我已经查看了许多关于此的示例,包括this,但我的示例有所不同,因为使用了单独的角度组件来生成内容。
app.component.html:
<div class="row" style="border:1px solid red;">
<div class="col d-flex justify-content-center">
<button mat-raised-button>text</button>
<app-child-component></app-child-component>
</div>
</div>
子组件.html:
<div *ngFor="let text of buttonText">
<button mat-raised-button>{{text}}</button>
</div>
子组件.ts:
buttonText = ['Button1', 'Button2', 'Button3'];
但我希望所有按钮都水平对齐: StackBlitz 示例: https ://stackblitz.com/edit/github-t6uyxp-z6is8f?file=src%2Fapp%2Fchild-component%2Fchild-component.component.ts
解决方案
只需将 display: flex 添加到包装容器:
最好添加类而不是内联样式。内联仅用于演示
<div style="display:flex">
<div *ngFor="let text of buttonText">
<button mat-raised-button>{{text}}</button>
</div>
</div>
推荐阅读
- c++ - 与静态成员相关的模板专业化错误
- python - 使用 Python,有没有更优雅的方法来查找列表中的第二大数字?
- javascript - javascript中未定义的数组变量
- android - 具有类似于活动的共享元素的片段转换
- python-3.x - 如何等到元素的文本更改为字符串以外的其他内容?
- node.js - [tokio-rs][documentation] 具有共享状态示例的多个异步“子应用程序”?
- angular - “可观察”类型上不存在属性“json”
' - javascript - C#和Webview控件,如何知道javascript何时完成?
- prometheus - 查询时如何指定 Prometheus 输出格式?
- reactjs - 组件选择器只能和 babel-plugin-emotion 一起使用 使用emotion时报错