Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular/material - how to get mat-toolbar shadow over the page content?

Tags:

html

css

angular

I currently have a standard layout for my app, toolbar with a fixed sidenav and content section. I have since discovered that I can get the drop shadow on the toolbar with the class inclusion mat-elevation-z4, however I cannot seem to get the shadow to overlay the content section when I have scrolled down in the section itself.

I have also attempted to use the z-index to correct this...

mat-toolbar I gave z-index: 2 and <div class="container"> I gave z-index: -1

If somebody could give me some advice, I would be grateful.

like image 401
physicsboy Avatar asked Feb 12 '18 09:02

physicsboy


People also ask

How do I change the mat toolbar color in angular materials?

The color of a <mat-toolbar> can be changed by using the color property. By default, toolbars use a neutral background color based on the current theme (light or dark). This can be changed to 'primary' , 'accent' , or 'warn' .

What is Mat toolbar row?

The <mat-toolbar> is an Angular Directive used to create a toolbar to show the title, header, or any button action of buttons. <mat-toolbar>: It represents the main container. <mat-toolbar-row>: It adds a new row at the toolbar. Example of ToolBar: ADVERTISEMENT.

What is class mat elevation z8?

the mat-elevation-z8 class is an Angular Material elevation class that allows you to add separation between elements along the z-axis.


2 Answers

The issue is because of the z-index. The toolbar is overshadowed by the content section which affects the box-shadow of toolbar. In order to keep the box-shadow visible, you need to give a higher z-index to toolbar (which you already did). But Z-index works on positioned elements, hence provide position to the .mat-toolbar.

Example:

.mat-toolbar {
  position: relative;
}
like image 90
K K Avatar answered Sep 19 '22 22:09

K K


Predefined CSS classes

The easiest way to add elevation to an element is to simply add one of the predefined CSS classes mat-elevation-z# where # is the elevation number you want, 0-24. Dynamic elevation can be achieved by switching elevation classes:

<div [class.mat-elevation-z2]="!isActive" [class.mat-elevation-z8]="isActive"></div>
like image 34
Rahul.S Avatar answered Sep 20 '22 22:09

Rahul.S