简体   繁体   English

如何将“position:sticky”应用于flex-layout中的角度材料卡?

[英]How to apply “position: sticky” to an angular-material card in a flex-layout?

I'm trying to get an angular-material card to be sticky. 我正试图让角质材料卡变得粘稠。 Problem is it didn't seem to work, and I don't get why. 问题是它似乎不起作用,我不明白为什么。

Is it because the parent component got a FxLayout ? 是因为父组件得到了FxLayout吗? I couldn't get my card to be sticky, here my code: 我无法让我的卡变粘,这是我的代码:

HTML HTML

<section fxLayout="row" fxLayoutGap="5%">
  <article class="progress-card" fxFlex="30">
    <mat-card fxLayout="column" fxLayoutAlign="center center">
      <mat-card-title><h2>PROGRESSION</h2></mat-card-title>
      <mat-card-content>
        <p>Text here</p>
      </mat-card-content>
    </mat-card>
  </article>
  <article fxFlex="70" fxLayout="column">
    <mat-card>
      <mat-card-title><h2>CONTENT</h2></mat-card-title>
      <mat-card-content>
        <p>Text here</p>
      </mat-card-content>
    </mat-card>
  </article>
</section>

CSS CSS

.progress-card {
  position: -webkit-sticky; /* Safari */
  position: sticky;
  top: 0;
}

I'd like to get the "progress-card" to stay sticky on the top of the screen as I scroll down to read the other card content. 当我向下滚动阅读其他卡内容时,我想让“进度卡”在屏幕顶部保持粘性。

Thanks for your help and your time. 感谢您的帮助和时间。

 section.stycky { position: -webkit-sticky; /* Safari */ position: sticky; top: 0; } body { height: 10000px; } 
 <section fxLayout="row" fxLayoutGap="5%" class="stycky"> <article class="progress-card" fxFlex="30"> <mat-card fxLayout="column" fxLayoutAlign="center center"> <mat-card-title><h2>PROGRESSION</h2></mat-card-title> <mat-card-content> <p>Text here</p> </mat-card-content> </mat-card> </article> </section> <section fxLayout="row" fxLayoutGap="5%"> <article fxFlex="70" fxLayout="column"> <mat-card> <mat-card-title><h2>CONTENT</h2></mat-card-title> <mat-card-content> <p>Text here</p> </mat-card-content> </mat-card> </article> </section> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM