Joan
Joan

Reputation: 243

Fixed ion-card on the top of the screen Ionic 3

I am trying to fix a card on the top of the screen. I am trying to do this on the <ion-content> but after several tries I am not solving it. I've tried with ion-fixed, but it doesn't work either.

I want to fix this part of the code:

<ion-card text-center>
   <ion-card-content>
      <h5 style=" font-size: 180%;"> {{selectedItem | noneSelectedItem}}
      </h5>
   </ion-card-content>
</ion-card>

Then, it follows a list:

<ion-card style="background-color:rgb(177, 55, 47);" >
   <br>
   <p class="titleCard">Lista de la carta</p>
   <ion-card-content>
      <ion-list class="accordion-list" >
         <!-- First Level -->
         <ion-list-header *ngFor="let item of information; let i = index" no-lines no-padding>
           <!-- Toggle Button -->
           <button ion-item (click)="toggleSection(i)" detail-none [ngClass]="{'section-active': item.open, 'section': !item.open}">
             <ion-icon item-left name="arrow-forward" *ngIf="!item.open"></ion-icon>
             <ion-icon item-left name="arrow-down" *ngIf="item.open"></ion-icon>
             {{ item.name }}
           </button>
      etc...

So my doubt is about how to put the first card fixed when I scroll the list.

Thank you so much.

Upvotes: 3

Views: 7297

Answers (1)

chiconese
chiconese

Reputation: 325

ion-content by deafult has native scroll, so you can only change ion-content to scroll or not. The solution (in your case) would be putting the card outside ion-content.

The ionic page structure in blocks/sessions:

<ion-header>
   <ion-navbar>
      <ion-title>Header</ion-title>
   </ion-navbar>
   <ion-toolbar>
      <ion-title>Subheader</ion-title>
  </ion-toolbar>
</ion-header>
<ion-content>
  ...
</ion-content>
<ion-footer>
  ...
</ion-footer>

What you need is to put one card in the Subheader, so do the following: Put the card that you want to set on top outside ion-content. Before ion-content use ion-toolbar.

<ion-header>
   <ion-navbar>
      <ion-title>Header</ion-title>
   </ion-navbar>
   <ion-toolbar>
      <ion-card text-center>
        <ion-card-content>
          <h5 style=" font-size: 180%;"> {{selectedItem | noneSelectedItem}}
          </h5>
        </ion-card-content>
      </ion-card>
  </ion-toolbar>
</ion-header>
<ion-content>
  THE REST OF YOUR CARDS
</ion-content>
<ion-footer>
  ...
</ion-footer>

OR try adding multiple headers:

<ion-header>
  <ion-title>Header</ion-title>
</ion-header>
<ion-header>
   <ion-card text-center>
            <ion-card-content>
              <h5 style=" font-size: 180%;"> {{selectedItem | noneSelectedItem}}
              </h5>
            </ion-card-content>
    </ion-card>
</ion-header>

Upvotes: 8

Related Questions