Ionic item with left and right aligned text

51,399

Solution 1

This can be done using basic CSS properties. there is nothing specic about ionic here. This can be done using float:left and float:right properties.

Still for your reference, you can go through this link.

Solution 2

In ionic 2 just use

text-left,text-right

<div class="item">
    <span text-left>first</span>
    <span text-right>second</span>
</div>

Read More :- https://github.com/driftyco/ionic/typography.scss

Solution 3

With Ionic 3 the above answers did not work. With ion-items you can simply leave the left text untouched because it is left-aligned by default. With the text that you want to right-align, simply use the item-end decorator like this:

<ion-item>
     Name <span item-end>Zack</span>
</ion-item>

Solution 4

I use Ionic 3 and the best anwser I think is to use the ionic tags and attributes:

<ion-list>
  <ion-item>
    <ion-label>
      this to the left
    </ion-label>
    <ion-label text-right>
      this to the right
    </ion-label>
  </ion-item>
</ion-list>

Solution 5

With Ionic 2 & above, you can use Element Placement Attributes like float-left or float-right on your HTML elements instead of adding properties like float: left; or float: right; on your scss

https://ionicframework.com/docs/theming/css-utilities/#float-elements

<div class="item">
  <span float-left>first</span>
  <span float-right>second</span>
</div>
Share:
51,399
user1283776
Author by

user1283776

Updated on March 09, 2020

Comments

  • user1283776
    user1283776 about 4 years

    I have an ionic item in an ionic list. What is the best way to left align the first text and right align the second text?

      <div class="item">
        <span>first</span>
        <span>second</span>
      </div>
    
  • user1283776
    user1283776 over 8 years
    Awesome! I am attaching the changes I did so that others who find this post can find it. I added this to my CSS document: .alignleft { float: left; } .alignright { float: right; } and then changed my HTML to this <div class="item"> <span class="alignleft">first</span> <span class="alignright">second</span> </div>
  • Anuj
    Anuj over 6 years
    for ionic 3. other example is not working in ionic 3
  • Amit Gandole
    Amit Gandole over 4 years
    Is it removed in ionic 4?