如何在离子网格内居中项目



我正在尝试居中(包括 horiz 和垂直(并堆叠 2 个社交按钮,但它不起作用。我做错了什么?

<ion-content padding>
  <ion-grid>
    <ion-row justify-content-center align-items-center>
      <ion-col>
        <button ion-button icon-left outline color="fb" (click)="fbClicked($event)">
  <ion-icon name="logo-facebook" color="#3B5998"></ion-icon>
  CONNECT WITH FACEBOOK
</button>
      </ion-col>
    </ion-row>
     <ion-row justify-content-center align-items-center>
      <ion-col>
        <button ion-button icon-left outline>
  <ion-icon name="logo-google"></ion-icon>
  CONNECT WITH GOOGLE
</button>
      </ion-col>
    </ion-row>
  </ion-grid>
</ion-content>

我不完全了解所有 ionic 内置的类,但在这种情况下您可以使用 flexbox,Android 和 ios 对此有很好的支持。我稍微更改了您的代码并简化了它。

angular.module('ionicApp', ['ionic'])
.controller('AppCtrl', function($scope, $ionicModal) {
  
});
.Aligner {
  display: flex;
  align-items: center;
  justify-content: center;
}
<html ng-app="ionicApp">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> 
    
    <title>Ionic</title>
    <link href="//code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet">
    <script src="//code.ionicframework.com/nightly/js/ionic.bundle.js"></script>
  </head>
  <body ng-controller="AppCtrl">
    
    <ion-header-bar class="bar-positive">
      <h1 class="title">Social Buttons</h1>
    </ion-header-bar>
    
    
<ion-content  class="Aligner">
  <ion-grid>
    <ion-row>
      <div class = "col">
        <button color="fb" (click)="fbClicked($event)">
  <ion-icon name="logo-facebook" color="#3B5998"></ion-icon>
  CONNECT WITH FACEBOOK
</button>
      </div>
      <div class = "col">
        <button>
  <ion-icon name="logo-google"></ion-icon>
  CONNECT WITH GOOGLE
</button>
      </div>
    </ion-row>
  </ion-grid>
</ion-content>
    
    
  </body>
</html>

相关内容

  • 没有找到相关文章

最新更新