Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to do horizontal scroll in ionic 3

look at my image

I have 10 names in the ion-scroll but it is coming to the next line like a paragraph.

here is my .html code.

<ion-scroll scrollX="true" style="width:100vw; height:50px" >
        <ion-row class="headerChip">
          <div *ngFor="let tabName of product_type; let idx = index" [ngClass]="showSelectedTabArray[idx].showSelectedTab ? 'headerChipGray' : 'headerChipGreen'">
          <ion-chip  (click)="changeData(tabName)">
          <ion-label  >{{tabName.languagename}}</ion-label>
          <div></div>
          </ion-chip>
          </div>
        </ion-row>
      </ion-scroll>

here is my css

.headerChipGray{
    ion-chip.chip.chip-md{
        margin: 2px 2px 2px 2px;
        border-radius: 10px;
        border: 1px solid gray;
        background: white;
    }
    ion-chip.chip.chip-ios{
        margin: 2px 2px 2px 2px;
        border-radius: 10px;
        border: 1px solid gray;
        background: white;
    }
}

.headerChipGreen{

    ion-chip.chip.chip-md{
        margin: 2px 2px 2px 2px;
        border-radius: 10px;
        background: white;
        color: #A80C50;
        border: 1px solid #A80C50;
    }

    ion-chip.chip.chip-ios{
        margin: 2px 2px 2px 2px;
        border-radius: 10px;
        background: white;
        color: #A80C50;
        border: 1px solid #A80C50;
    }
}

this same piece of code used to work in ionic 2 after updating to ionic 3 i am facing this issue what i am missing ionic doc for ion-scroll

like image 667
Mohan Gopi Avatar asked May 06 '17 06:05

Mohan Gopi


People also ask

How do I enable scrolling in ionic?

1 Answer. Show activity on this post. simply added overflow-scroll="false" in ion-content.

How do I scroll horizontally in CSS?

To enable horizontal scrolling, we can use the CSS property overflow-x. If we assign the value scroll to the overflow-x property of the container element, the browser will hide horizontally overflowing content and make it accessible via horizontal scrolling.


2 Answers

This simple CSS styling will get your job done more easier. Wrap your content inside a div and add the below styling to that div. This should work irrespective of any Ionic version. However, I'm using Ionic 5.

CSS / SCSS

.horizontal-scroll {
    overflow: auto;
    white-space: nowrap;
}

HTML

<div class="horizontal-scroll">
  <ion-chip>
    <ion-label>Java</ion-label>
  </ion-chip>
  <ion-chip>
    <ion-label>Node.js</ion-label>
  </ion-chip>
  <ion-chip>
    <ion-label>Fusion.js</ion-label>
  </ion-chip>
  <ion-chip>
    <ion-label>React</ion-label>
  </ion-chip>
  <ion-chip>
    <ion-label>Redux</ion-label>
  </ion-chip>
  <ion-chip>
    <ion-label>Angular</ion-label>
  </ion-chip>
  <ion-chip>
    <ion-label>JavaScript</ion-label>
  </ion-chip>
</div>

You can check here for working example that I've created.

like image 117
coderpc Avatar answered Sep 30 '22 21:09

coderpc


It looks like ion-row within your scroll is wrapping the items.

Try using nowrap attribute.

Adds flex-wrap: nowrap. Forces the columns to a single row.

<ion-scroll scrollX="true" style="width:100vw; height:50px" >
  <ion-row nowrap class="headerChip">
    <div *ngFor="let tabName of product_type; let idx = index" [ngClass]="showSelectedTabArray[idx].showSelectedTab ? 'headerChipGray' : 'headerChipGreen'">
    <ion-chip  (click)="changeData(tabName)">
    <ion-label  >{{tabName.languagename}}</ion-label>
    <div></div>
    </ion-chip>
    </div>
  </ion-row>
</ion-scroll>
like image 40
Suraj Rao Avatar answered Sep 30 '22 19:09

Suraj Rao