Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ionic - How to wordwrap a long string in ion-header

This is my code, and I tried text-wrap , inside ion-header still can not show whole title.

<ion-header>
  <ion-toolbar text-wrap color="danger">
    <ion-buttons>
        <button ion-button navPop icon-only>
            <ion-icon ios="ios-arrow-back" md="md-arrow-back"></ion-icon>
        </button>
    </ion-buttons>
    <ion-title>{{new.title}}</ion-title>
  </ion-toolbar>
</ion-header>

enter image description here

Update

<ion-header>
  <ion-toolbar color="danger">
    <ion-buttons>
        <button ion-button navPop icon-only>
            <ion-icon ios="ios-arrow-back" md="md-arrow-back"></ion-icon>
        </button>
    </ion-buttons>
    <ion-item color="danger" text-wrap>
     <ion-title >{{new.title}}</ion-title>
    </ion-item>
  </ion-toolbar>
</ion-header>

I tried add ion-item there, but still not working for me. enter image description here

Update 2

.ios .toolbar-title {
   text-overflow: inherit;
   white-space: normal;
   text-align: left;
   font-size:1.3em;
}

.md .toolbar-title {
   text-overflow: inherit;
   white-space: normal;
   text-align: left;
   font-size:1.3em;
}

enter image description here

like image 883
Yuyang He Avatar asked Aug 14 '17 08:08

Yuyang He


3 Answers

A little neater than Finesse's answer (for Ionic 5):

<ion-title>
  <div class="ion-text-wrap">
    {{new.title}}
  </div>
</ion-title>
like image 120
AndrWeisR Avatar answered Sep 18 '22 02:09

AndrWeisR


Pls update your css file as below :

.toolbar-title {
   text-overflow: inherit;
   white-space: normal;
}

Edited:

Or

.toolbar-title {
   text-overflow: unset;
   white-space: unset;
}
like image 37
Mankeomorakort Avatar answered Sep 19 '22 02:09

Mankeomorakort


Add an extra wrapper to you <ion-title> content to enable the wrapping:

<ion-title>
  <div style="white-space: normal;">
    {{new.title}}
  </div>
</ion-title>

Additionally, if you want the title to extend the header when there is too much text, add the following CSS code:

ion-title {
  position: static;
}
like image 21
Finesse Avatar answered Sep 19 '22 02:09

Finesse