Ionic 4 Grid Tutorial by Example

Ionic UI components prove very helpful in quickly creating responsive view layouts compatible with almost all screen sizes.

But some times we may need a gid system like we rows and columns are popularly known in bootstrap for better and tight distribution of elements Horizontally and Vertically on an app page.

Ionic provides a well-trained Grid system for such tasks.

The ion-grid provides a flexbox custom layout. It is having mainly three components a grid, rows, and columns.

Columns are placed horizontally in a row which can fit automatically by resizing their wdth according to available space in that row.

By default 12 columns can be added in a row but can be customized which we will see in further examples.

Creating Grids:

The simple grid can be created using the following template on the page:

A grid is a set of rows with columns which can be created using the following component directives:

IonGrid

The ion-grid is used to add a wrapper around rows and columns of the grid. Under grid wrapper rows are added as vertical structures which is divided into columns to occupy horizontal space to fill row area.

Properties:

 

IonRow

The ion-row component is used to create a single row in the grid layout. Rows are the horizontal structure with varying numbers of columns to fill full row width.

By default columns in the row can take full space horizontally and wrap columns to the next line if squeezed. By using the below properties we can modify CSS flexbox properties to override the default behavior.

Properties:

fixed: Takes boolean value; If set to true the grid will have fixed width on the screen size.

Column Wrapping:

nowrap: If nowrap property is added on ion-row, columns will not drop to the next line; Adds CSS property flex-wrap: nowrap.

wrap-reverse: The columns will wrap in reverse. Adds css property flex-wrap: wrap-reverse.

Vertically alignment of columns

align-items-start: All columns will be vertically aligned at the top unless they specify their own alignment. Adds css property flex-wrap: nowrap.

align-items-center: All columns will be vertically aligned in the center, unless they specify their own alignment.Adds CSS property flex-wrap: nowrap.

align-items-end: All columns will be vertically aligned at the bottom unless they specify their own alignment.; Adds css property flex-wrap: nowrap.

align-items-stretch: All columns will be stretched to take up the entire height of the row unless they specify their own alignment.; Adds CSS property align-items: stretch.

align-items-baseline: All columns will be vertically aligned at their baselines unless they specify their own alignment.; Adds CSS property align-items: baseline.

Horizontal alignment of columns

justify-content-start: All columns will be horizontally aligned at the start.; Adds CSS property justify-content: start.

justify-content-center: All columns will be horizontally aligned at the center.; Adds CSS property justify-content: center.

justify-content-end: All columns will be horizontally aligned at the end.; Adds CSS property justify-content: end.

justify-content-around: Adds justify-content: space-around. All columns will be horizontally aligned with equal space around them.; Adds CSS property justify-content: space-around.

justify-content-between: Adds justify-content: space-between. All columns will be horizontally aligned with a half-size space on either end.; Adds CSS property justify-content: space-between.

IonCol

The ion-col component creates a cell/ column in the row. Columns are added inside of a row. They occupy the entire available row space which is divided by columns added in the row.

Column alignment can be modified by using the below properties:

align-self-start: The column will be vertically aligned at the top; Adds CSS property align-self: flex-start.

align-self-center: The column will be vertically aligned in the center; Adds CSS property align-self: center.

align-self-end: The column will be vertically aligned at the bottom; Adds CSS property align-self: flex-end.

align-self-stretch: The column will be stretched to take up the entire height of the row; Adds CSS property align-self: stretch.

align-self-baseline: The column will be vertically aligned at its baseline; Adds CSS property align-self: baseline.

size: The number of column space it will take out of total available column slots i:e 12. The default is set to auto to auto-adjust according to available space in the row.

offset: Amount of margin added on column start based on total columns available in that row.

pull: This adds right CSS property to pull column towards the start of the total available

push: This adds left CSS property to colum and push towards the end of row.

Thanks for visiting :) Let me know if you have some suggestions or feedback for this post in the comment section. Looking for any tutorial or demo on FreakyJolly, just drop me a message here

Leave a Reply

avatar
  Subscribe  
Notify of