How can i make an object center in <ion-col>?

Hello,
i want make some images or icones center in ionic 2 column dont know how! nothings works really!
can i get help plz!
ty

2 Likes

text-align: center should work

1 Like

i want make a thumbnail center in his column text align doesn’t work …!.

when you said ionic 2 column i assumed u were using
<ion-row><ion-col>

With that in mind, thats how i aligned my text columns on last project:

HTML
<ion-grid><ion-row><ion-col></ion-col></ion-row></ion-grid>

CSS:
ion-row {
text-align: center;
}

The same work with divs.
What element are u using?

4 Likes

This does not work for me. I’m trying to make a grid of avatars that is centre-balnced… I have the following structure:

<ion-grid no-padding>
  <ion-row no-padding justify-content-start align-items-start>
    <ion-col ion-item no-lines no-padding text-center col-2 *ngFor="let item of items | slice:0:12"> 
      <ion-avatar>
        <img draggable="false" [src]="item.thumbnail">
      </ion-avatar>
    </ion-col>
  </ion-row>
</ion-grid>

It seems no matter what I do with css or ionic utilities… I just cannot get the avatars to center…

PLEASE HELP!

<img style=“margin: auto” …

7 Likes

.ele {
margin: 0 auto;
}

1 Like

Hello,

Add the image into a DIV with a style : text-align= “center”

you ca also add valign=“center” to IMG after that if you want to center it vertically.

cheers.

1 Like

I skip ion grid and go for css grid or flexbox

Better documented

Tom

Something would be like this:

ion-col.center-any-object {
display: flex;
justify-content: center;
}

8 Likes

That worked for me. I was trying to center align two buttons stacked side by side inside the same ion-col.

<ion-col class="ion-text-center"> </ion-col>

3 Likes

ion-col has 100% width by default therefore it fills up the total width of ion-row.
if you want to center ion-col in ion-row you should add size=“auto” so it wraps it’s content.

<ion-grid no-padding>
  <ion-row no-padding justify-content-start align-items-start>
    <ion-col size="auto" ion-item no-lines no-padding text-center col-2 *ngFor="let item of items | slice:0:12"> 
      <ion-avatar>
        <img draggable="false" [src]="item.thumbnail">
      </ion-avatar>
    </ion-col>
  </ion-row>
</ion-grid>

This does work for only text. I guess. Not others,