Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make ion-item allow overflow in Ionic 2?

I want to make ion-item allow overflow of it's contents. I tried the following css (scss to be specific)

ion-item{
   overflow: visible;
   height : 220px;
}

but it doesn't seem to work.

I also tried adding overflow : visible property to the elements generated by ion-item (like .item-inner, .item-block), but that didn't work too.

Edit (Adding code snippets)

home.html

<ion-header>
  <ion-navbar>
    <ion-title>
      Ionic Blank
    </ion-title>
  </ion-navbar>
</ion-header>

  <ion-content padding>
    <div class="rel-container">
      <ion-list>
        <ion-item>
          <div>Name1</div>
          <div>Name2</div>
          <div>Lorem ipsum dolor</div>
          <div class="error-container">
            <div class="error">a quick brown fox</div>
          </div>
        </ion-item>
      </ion-list>
    </div>
  </ion-content>

home.scss

ion-item,ion-list,ion-label, .item-md, .item-block, .item, .item-inner, .input-wrapper, .rel-container, .button-effect{
    overflow: visible;
}

page-home {
    ion-item{
        height: 9rem;
    }


    .error-container{
        padding: 5px;
        background: red;
        color: white;
        position: absolute;
        z-index: 400;
    }

    .rel-container{
        position: relative;
    }
}
like image 954
Adesh Atole Avatar asked Jun 07 '17 17:06

Adesh Atole


2 Answers

Before I answer, here are some miscelleneous details

Ionic v3.3.0
Angular v4.1.2

The problem that overflow was not working as expected, was the CSS property contain : content; applied by Ionic for .item.

(More info here: https://developer.mozilla.org/en-US/docs/Web/CSS/contain)

To solve this I just had to override it with

.item {
    contain:none;
}

Peace! ✌️✌️✌️

like image 89
Adesh Atole Avatar answered Nov 12 '22 21:11

Adesh Atole


You can just add the text-wrap directive:

<ion-item text-wrap>
Multiline text that should wrap when it is too long
to fit on one line in the item.
</ion-item>

https://ionicframework.com/docs/api/components/item/Item/

like image 2
Scott Avatar answered Nov 12 '22 22:11

Scott