Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to align ion-avatar to the center of <ion-item> in Ionic 4

I am working in my Ionic 4 project and I have added the ion-avatar but it is not coming in the center of the

This is my editprofile.page.html:

<ion-item class="newitem2">
    <ion-avatar>
        <img name="profile_pic" [src]="this.userdetailsedit.value.profile_pic"/>
    </ion-avatar>   
</ion-item>

Any help is much appreciated.

like image 470
Rahul Pamnani Avatar asked Mar 20 '19 11:03

Rahul Pamnani


People also ask

How do I align an image in center in ionic?

You can use ionic CSS utilities to align center by applying the attribute text-center to the parent element of the one you want to center horizontally. In your case I would wrap the <img> in a <div> so that it affects only the image and not the <p> elements. Show activity on this post.

How do you increase the size of ions in Avatar?

Avatars can be used by themselves or inside of any element. If placed inside of an ion-chip or ion-item , the avatar will resize to fit the parent component.

How do I disable ion items?

Simply give pointer-events:none css to disable click. Show activity on this post. This will remove ripple effect but will keep the element clickable. For example, you can have ion-checkbox inside ion-item and pointer-events:none; will prevent from clicking on it which might not be the behaviour that you need.

How do you show a list in ionic?

Sliding List: Sliding elements can swipe left or right to reveal a set of hidden buttons. To use a sliding item, add a <ion-item-sliding> element inside of an <ion-list> element. Next, add a <ion-item-options> element within the slider to accommodate the buttons. By default, the buttons are on the right side.


1 Answers

please add class on ion-avatar

your html file looks like

<ion-item class="newitem2">
    <ion-avatar class="image-center">
        <img name="profile_pic" [src]="this.userdetailsedit.value.profile_pic"/>
    </ion-avatar>   
</ion-item>

add this scss

.image-center{
margin:0 auto;
}
like image 193
Jatin Devani Avatar answered Sep 27 '22 19:09

Jatin Devani