如何将物品置于离子网内?

时间:2017-04-04 17:14:02

标签: javascript css ionic-framework sass ionic2

我试图居中(水平和垂直)并堆叠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>

1 个答案:

答案 0 :(得分:0)

我并不完全了解所有离子内置类,但你可以使用flexbox这个案例和android和ios有很好的支持。我改变了你的代码并简化了它。

&#13;
&#13;
angular.module('ionicApp', ['ionic'])

.controller('AppCtrl', function($scope, $ionicModal) {
  

});
&#13;
.Aligner {
  display: flex;
  align-items: center;
  justify-content: center;
}
&#13;
<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>
&#13;
&#13;
&#13;