Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
730 views
in Technique[技术] by (71.8m points)

angular material - How to have scrolling after mat-toolbar

I have mat-toolbar, so here i want the scrolling on the page to happen after mat-toolbar. so that mat-toolbar remains as fixed header. So that even if i scroll down i see the toolbar.

<mat-toolbar style="flex: 0 0 128px;" color="primary">
        <button mat-icon-button aria-label="Back" routerLink="/reports">
            <mat-icon>arrow_back</mat-icon>
        </button>
        <mat-card-title>Upload Report</mat-card-title>
    </mat-toolbar>
<div>
//other form elements
</div>
question from:https://stackoverflow.com/questions/65560024/how-to-have-scrolling-after-mat-toolbar

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Wrapping the toolbar and the other content in a CSS grid - having 100% height - will work, making both a grid row where the toolbar has auto height and the other content has overflow:auto.

<div class="container">
    <mat-toolbar>
        <h1>
            Fixed Angular Material toolbar
        </h1>
    </mat-toolbar>
    <main>
        <p>
            This is the main content which is scrollable because the main content has 'overflow-y: auto' and is a grid row
            with a height of 1fr (the container is a CSS grid). This only works when the container div has a height of 100%.
        </p>
    </main>
</div>
.container {
    height: 100%;
    display: grid;
    grid-template-rows: auto 1fr; // mat-toolbar main
}

/* Grid row 1 */
mat-toolbar {

}

/* Grid row 2 */
main {
    overflow-y: auto;
    padding: 1rem;
}

Here is a working example: https://www.jitblox.com/design/MdTqMjv9Pr


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...