Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic - Center text vertically in item-list with item-avatar class

I try to add a Ion-List to my apllication with items build like |Image|Text|Button

The Image and the Button get centerd vertically, but the text does not.

I tried some CCS found on the Internet, which works fine in Browser preview but not on a real device (Samsung Galaxy S3 Mini, Android 4.1.2)

style="position: absolute; top: 50%; transform: translateY(-50%);"

Code

    <ion-content>
       <ion-list>
       <ion-item class="item-avatar item-icon-right" collection-repeat="x in y" href="#/pages/{{x.id}}">
        <img src="img/{{x.icon}}.png">
        <div style="position: absolute;   top: 50%; transform: translateY(-50%);">{{x.name}}</div>
        <i class="icon ion-chevron-right icon-accessory"></i>
        </ion-item>
      </ion-list>
   </ion-content>

On Device

device screenshot

like image 759
Mariano Schmands Avatar asked Oct 03 '15 10:10

Mariano Schmands


2 Answers

You can try to use this css:

.item-text-center
{
    display: -webkit-box;
    display: -webkit-flex;
    display: -moz-box;
    display: -moz-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    -webkit-align-items: center;
    -moz-align-items: center;
    align-items: center;
    position: absolute;
    top: 0;
    height: 100%;
}

and apply it to your <div>

<div class="item-text-center item-text-wrap">{{x.name}}</div>

and this is the whole content:

  <ion-content class="padding">
    <ion-list>
      <ion-item class="item-thumbnail-left item-icon-right" collection-repeat="x in y">
        <img src="img/{{x.icon}}.png">
        <div class="item-text-center item-text-wrap">{{x.name}}</div>
        <i class="icon ion-chevron-right icon-accessory"></i>
      </ion-item>
    </ion-list>
  </ion-content>

This ionic play might help you.

like image 77
LeftyX Avatar answered Jan 22 '23 09:01

LeftyX


line-height works for me

css:
.item-text-center-vertical {
  line-height: 300%;
}

Inside avatar:
<h2 class="item-text-center-vertical">{{value}}</h>
like image 32
Long Sang Chan Avatar answered Jan 22 '23 10:01

Long Sang Chan