css - 固定 ionic 卡在屏幕 Ionic 3 的顶部

标签 css ionic-framework scroll css-position

我正在尝试在屏幕顶部固定一张卡片。我正在尝试在 <ion-content> 上执行此操作但经过几次尝试,我没有解决它。我试过 ion-fixed , 但它也不起作用。

我想修复这部分代码:

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

然后,它遵循一个列表:

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

所以我的疑问是当我滚动列表时如何固定第一张卡片。

非常感谢。

最佳答案

ion-content默认有原生滚动,所以你只能改变ion-content是否滚动。解决方案(在您的情况下)是将卡放在 ion-content 之外。

block / session 中的 ionic 页面结构:

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

您需要将一张卡片放在Subheader 中,因此请执行以下操作: 将要设置的卡片放在 ion-content 之外。 在ion-content之前使用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>

或者尝试添加多个 header :

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

关于css - 固定 ionic 卡在屏幕 Ionic 3 的顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47097649/

相关文章:

javascript - jQuery 移动端与scrollTop 的bug

html - CSS使图像水平和垂直居中而不调整大小

css - 在 calc (css) 中使用 screen.width

jquery - 单页网站 - 使内容适合 100% 的屏幕

html - 如何在 rails 4 中将部分表单呈现为水平表单

html - 两个独立滚动的div

c# - ListView 页脚行 - 水平滚动

android - ionic : No 'Access-Control-Allow-Origin' header is present on the requested resource

cordova - ionic 实时重新加载错误

android - 未知的 Chrome 错误 : 0