Ionic item with left and right aligned text

2020-07-06 01:52发布

问题:

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>

回答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.



回答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



回答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>


回答4:

You also use ionic's class and attribute to do that. For exemple

<div class="item row">
   <span align="right" class="col col-50">first</span>
   <span align="left" class="col col-50">second</span>
</div>


回答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>


回答6:

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>


回答7:

Ionic uses CSS Utilities. They provide their own way of aligning text.

<div class="item">
  <span>first</span>
  <span>second</span>
</div>

More about CSS utilities at https://ionicframework.com/docs/theming/css-utilities/#text-alignment



回答8:

you can use css "text-align" property to do that

<div class="item row">
  <span style="text-align:right" class="col col-50">first</span>
  <span style="text-align:left" class="col col-50">second</span>
</div>

Hope this fix your problem