html - How to center a row of ion-fabs?
问题描述
I want to center vertically and horizontally this row of ion-fabs, but at the moment it sits on the top and into the start position, I've tried every single html/css trick, but it doesn't work. I have to mention that I'm working it on a modal (I don't know if it's relevant or not, but whatever) soo, here's my example
<ion-content padding>
<ion-grid>
<ion-row>
<ion-col>
<ion-fab-button size="large" fab-fixed color="danger">
<ion-icon name="trash-outline"></ion-icon>
</ion-fab-button>
</ion-col>
<ion-col>
<ion-fab-button size="large" fab-fixed color="primary">
<ion-icon name="camera-outline"></ion-icon>
</ion-fab-button>
</ion-col>
<ion-col>
<ion-fab-button size="large" fab-fixed color="secondary">
<ion-icon name="image-outline"></ion-icon>
</ion-fab-button>
</ion-col>
</ion-row>
</ion-grid>
</ion-content>
解决方案
Using CSS Flexbox to horizontally and vertically align the column content along the main and cross axis seems to do the trick. I wasn't sure if you were using the ionic-framework with React or Angular but after getting into a sandbox environment, I found out it was indeed angular by the casing of the tag names.
Here is the StackBlitz Demo to have a look at.
I included a code snippet below but the icons aren't rendering in so I added some text to show everything is still working in terms of vertically/horizontally centering. The ionic-framework isn't included so the ion-grid
also is not styling correctly but just look at the StackBlitz sandbox link for a better representation.
ion-col {
border: 1px solid grey;
height: 8rem; /* alter or remove this */
display: flex;
justify-content: center;
align-items: center;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<ion-app>
<ion-header>
<ion-toolbar>
<ion-title>Flexbox Centering Demo</ion-title>
</ion-toolbar>
</ion-header>
<ion-content padding>
<ion-grid>
<ion-row>
<ion-col>
<ion-fab-button size="large" fab-fixed color="danger">
Some Text
<ion-icon name="trash-outline"></ion-icon>
</ion-fab-button>
</ion-col>
<ion-col>
<ion-fab-button size="large" fab-fixed color="primary">
Some Text
<ion-icon name="camera-outline"></ion-icon>
</ion-fab-button>
</ion-col>
<ion-col>
<ion-fab-button size="large" fab-fixed color="secondary">
Some Text
<ion-icon name="image-outline"></ion-icon>
</ion-fab-button>
</ion-col>
</ion-row>
</ion-grid>
</ion-content>
</ion-app>
推荐阅读
- python - 使用 python3 时出现 Lambda 函数错误
- php - 如何在我的网站上加载另一个网站的验证码?
- angularjs - 我想在角度 js 中选择列表项时显示模式窗口
- python - 当我尝试运行 tensorflow 时,我注意到 GPU 没有被使用,尽管我使用的是 tensorflow GPU 版本。有什么解决方法吗?
- kotlin - 已添加片段:GalleryFragment{ef2fd8d #6 id=0x7f090081
- javascript - 应该如何构建 HTML 的布局以便在 D3 中有多个相互关联的图表
- c++ - 检测我是在构建可执行文件还是动态库?
- json - 如何在golang中将字符串转换为json?
- python - 连接字符串和整数
- pdf - 如何使用 iText 7 将源 PDF 内容添加到目标 PDF 而不会丢失页眉和页脚?