【问题标题】:Ionic (React) IonIcon - Unable to align to the center离子(反应)IonIcon - 无法对齐到中心
【发布时间】:2020-05-05 04:04:31
【问题描述】:

我正在尝试将图标与 Ionic (React) 中的中心对齐。但如屏幕截图所示,图标粘在左侧:

多伦多证券交易所代码:

type WalletBtnProps = {
  icon: { ios: string; md: string };
  label: string;
};

class WalletBtn extends React.Component<WalletBtnProps> {
  render() {
    return (
      <div className="wallet-button ion-text-center">
        <IonIcon icon={this.props.icon} />
        <IonLabel>{this.props.label}</IonLabel>
      </div>
    );
  }
}

CSS:

.wallet-button {
  width: 100%;
  text-align: center;
  height: auto;
  background: rgba(190, 164, 164, 0.2);
  border-radius: 10px;
  padding: 15px;
}
.wallet-button * {
  display: block !important;
}
.wallet-button ion-icon {
  font-size: 64px;
}

关于如何解决此问题的任何建议?

【问题讨论】:

    标签: css reactjs typescript ionic-framework ionic4


    【解决方案1】:

    您可以使用ion-tab-button,它会自动将标签居中并放置在图标下方。

    <div className="wallet-button">
      <IonTabButton>
        <IonIcon icon={this.props.icon} />
        <IonLabel>{this.props.label}</IonLabel>
      </IonTabButton>
    </div>
    
    .wallet-button {
      width: 100%;
      background: rgba(190, 164, 164, 0.2);
      border-radius: 10px;
      padding: 15px;
    }
    

    【讨论】:

      【解决方案2】:

      在图标类中添加这些css:

      width:100%;
      display:flex;
      align-items:center;
      justify-content:center;
      

      这些应该可以解决您的问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-05-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-19
        • 2022-09-25
        • 2013-05-30
        相关资源
        最近更新 更多