Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to align ion-label to right?

Tags:

ionic2

I am working on Ionic v2 and and facing issue in aligning ion-label value to the right. Following is the code snippet:

Html Code:

<ion-content padding class="home">
    <ion-list>
        <ion-item class="clearme">
            <ion-label>Employee Name:</ion-label>
            <ion-label class="alignme">Gaurav</ion-label>
        </ion-item>
    </ion-list>

CSS:

.home {
    background-color: red;
}
    
.alignme {
    float:right !important;
}

.clearme {
    clear: both !important;
}

After adding these classes text is not getting aligned to right.

like image 330
mobigaurav Avatar asked Aug 31 '16 13:08

mobigaurav


People also ask

How do I right align text in a label?

Align the text left or right Select the text that you want to align. On the Home tab, in the Paragraph group, click Align Left or Align Right .

How do you align ION label centers?

The new recommended way is to apply this using class="ion-text-center" . This is because you can't add these directives like text-center in React or Vue so they standardised on using classes for everyone.

How do I align a label to the right in CSS?

Solutions with CSS properties We specify the margin-bottom of our <div> element. Then, we set the display of the <label> element to "inline-block" and give a fixed width. After that, set the text-align property to "right", and the labels will be aligned with the inputs on the right side.


2 Answers

You can also use text-right attribute directive like below.

<ion-label text-right>Gaurav</ion-label>

For detail information about attribute directives, see here

Edit for Ionic 5

<ion-label class="ion-text-right">...</ion-label>
like image 96
abdllhbyrktr Avatar answered Oct 21 '22 22:10

abdllhbyrktr


Just use text-align instead of float.

.alignme {
    text-align: right;
}

Btw you should use ion-label only with forms - ion-input, ion-checkbox etc.

like image 33
edi_smooth Avatar answered Oct 21 '22 23:10

edi_smooth