【发布时间】:2019-12-24 11:11:46
【问题描述】:
<ion-label> 中的文本如何在 Ionic 4 的 <ion-list-header> 元素中水平居中?
我找到了如下所示的 text-center 属性实用程序,并记录在 ionic doc 中,但它不起作用。
我也尝试添加class="ion-center-text"。
但是当<ion-label> 在<ion-list-header> 中时,这两种测试都不起作用。
但是,如果 <ion-label> 被包裹在 <ion-item> 中,这将很有效!
<ion-list-header text-center>
<ion-label>Text not centered</ion-label>
</ion-list-header>
或:
<ion-list-header>
<ion-label text-center>Text still not centered</ion-label>
</ion-list-header>
或
<ion-list-header>
<ion-label class="ion-text-center">Text still not centered</ion-label>
</ion-list-header>
或
<ion-list-header class="ion-text-center">
<ion-label>Text still not centered</ion-label>
</ion-list-header>
我只需要一个简短而干净的解决方案来将我的 <ion-label> 集中在一个 <ion-list-header> 中。
有人有与 ionic 4 的“最佳实践”相匹配的解决方案吗?
在@annaya 的帮助下找到的解决方案是在display:block 上更改<ion-list-header> 的显示模式,或者更好地保留display:flex 并添加justify-content:center。
像这样:
<ion-list-header>
<ion-label>Text centered</ion-label>
</ion-list-header>
与:
list-item-header{
justify-content: center;
}
感谢回复、cmets 和英文更正;)
【问题讨论】:
标签: ionic-framework label ionic4