ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

ion-grid/ion-col/ion-row width attribute behaving unexpectedly

Open savanvadalia opened this issue 10 years ago • 4 comments

Short description of the problem:

ion-grid is not assigning the correct width to its child elements randomly.

What behavior are you expecting?

I expect correct width to be applied

Steps to reproduce:

  1. Use any ionic starter project
  2. Input the working code below in any page, this code will splits the buttons width into 20% and 80% as expected.
  3. Now Replace the code with not working code below which should ideally splits the buttons width into 30% and 70% as expected but it splits to 50%-50%

Working Code

<ion-header>
  <ion-navbar>
    <ion-title>
      Contact
    </ion-title>
  </ion-navbar>
</ion-header>

<ion-content>
  <ion-grid>
    <ion-row>
      <ion-col width-20>
        <button ion-button block (click)="verifyLogin()">Sign In</button>
      </ion-col>
      <ion-col width-80>
        <button ion-button block (click)="openUserRegistration()">Sign Up</button>
      </ion-col>
    </ion-row>
  </ion-grid>
</ion-content>

Not working code

<ion-header>
  <ion-navbar>
    <ion-title>
      Contact
    </ion-title>
  </ion-navbar>
</ion-header>

<ion-content>
  <ion-grid>
    <ion-row>
      <ion-col width-30>
        <button ion-button block (click)="verifyLogin()">Sign In</button>
      </ion-col>
      <ion-col width-70>
        <button ion-button block (click)="openUserRegistration()">Sign Up</button>
      </ion-col>
    </ion-row>
  </ion-grid>

</ion-content>

Which Ionic Version? 1.x or 2.x 2.x

System Information Cordova CLI: 6.4.0 Ionic Framework Version: 2.0.0-rc.3 Ionic CLI Version: 2.1.8 Ionic App Lib Version: 2.1.4 Ionic App Scripts Version: 0.0.45 ios-deploy version: Not installed ios-sim version: Not installed OS: Windows 7 Node Version: v6.9.1 Xcode version: Not installed

savanvadalia avatar Nov 18 '16 06:11 savanvadalia

This is correct behavior. width-30and width-70 are not valid column percentage attributes. See here for a list of valid attributes: http://ionicframework.com/docs/v2/components/#grid

ghost avatar Nov 18 '16 08:11 ghost

@savanvadalia , you can make it as you want without width-* attributes, only with css. So you need to set flex-basis property to 30% and 70% for particular col.

vitaliy-bobrov avatar Nov 18 '16 10:11 vitaliy-bobrov

Another option is to add css rules to your styles for width-30 and width-70 attributes for ion-col, it should be something like this:

ion-col {
&[width-30] {
flex: 0 0 30%;
max-width: 30%;
}

&[width-70] {
flex: 0 0 70%;
max-width: 70%;
}
}

vitaliy-bobrov avatar Nov 18 '16 10:11 vitaliy-bobrov

Thank you all for your comments.

@manucorporat I am new to ionic world and started with Ionic 2 itself first, Is there more detailed documentation for a reasoning the behind these set widths only? Would like to learn more about it to gain better understanding.

savanvadalia avatar Nov 20 '16 23:11 savanvadalia