Achieving a persistent footer at the bottom of the page within Material Angular's mat-sidenav-container while using the router-outlet

I am looking to keep my ngx-audio-player fixed at the bottom of the screen, similar to what you see on most music streaming websites. I currently have a structure with divs and various elements for dynamic content and playing music.

The issue is that the height of the div containing the content varies based on the visited link, causing the ngx-audio-player to move up and down accordingly. I want to ensure that the audio player remains at the bottom of the screen, leaving space for a side navigation menu on the left side.

I need a solution where only the content div will scroll if it exceeds the screen height, without affecting the position of the audio player.

To achieve this, here is the CSS snippet along with the HTML structure:

.sidenav-container {
  height: 100%;
}

.sidenav {
  width: 200px;
}

.sidenav .mat-toolbar {
  background: inherit;
}

.mat-toolbar.mat-primary {
  position: sticky;
  top: 0;
  z-index: 1;
}

.router-link-active{
  background-color: #aaa7b4;
}

.example-spacer {
  flex: 1 1 auto;
  text-align: center;
}
<mat-sidenav-container class="sidenav-container" >
  
  <mat-sidenav #drawer class="sidenav" fixedInViewport
      [attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
      [mode]="(isHandset$ | async) ? 'over' : 'side'"
      [opened]="(isHandset$ | async) === false">
    <mat-toolbar>Menu</mat-toolbar>
    <mat-nav-list *ngIf="!anyrole">
      <a *ngFor="let item of menuItems" mat-list-item [routerLink]="'/'+item" routerLinkActive="router-link-active"> {{item | titlecase}} </a>
    </mat-nav-list>
    <mat-nav-list *ngIf="anyrole">
      <a *ngFor="let item of menuItems" mat-list-item [routerLink]="'/admin/'+item" routerLinkActive="router-link-active"> {{item | titlecase}} </a>
      <amplify-sign-out></amplify-sign-out>
    </mat-nav-list>
  </mat-sidenav>
  <mat-sidenav-content>
    <mat-toolbar color="primary">
    <button
        type="button"
        aria-label="Toggle sidenav"
        mat-icon-button
        (click)="drawer.toggle()"
        *ngIf="isHandset$ | async">
        <mat-icon aria-label="Side nav toggle icon">menu</mat-icon>
      </button>
      <span  >Organization Name</span>
      <mat-form-field *ngIf="!orgName" class="example-spacer" appearance="fill">
        <mat-label >Select School</mat-label>
        <mat-select name="schoolId" [(ngModel)]="selectedSchool" (selectionChange)="refreshId($event.value)">
          <mat-option *ngFor="let school of facilitatorSchool" [value]="school.id">
            {{school.name}} 
          </mat-option>
        </mat-select>
      </mat-form-field>   

      <span *ngIf="orgName" class="example-spacer">{{orgName}}</span>
      <span >Hi {{currentUserName}}</span>
    </mat-toolbar>
    <router-outlet></router-outlet>
    
      <app-player fixedInViewport></app-player>
   
  </mat-sidenav-content>
 
</mat-sidenav-container>

Answer №1

To improve the functionality of your router-outlet, consider enclosing it within a tag as shown below:

<div class="my-div">
  <router-outlet></router-outlet>
</div>

The my-div element will define the space for the router. For instance:

my-div{
  top: 0;
  left: 0;
  position: absolute;
  width: 100vw;
  height: calc(100vh - $navbar - $controls);
  max-height: calc(100vh - $navbar - $controls);
  scroll-y: auto;
}

Ensure to update the values of navbar and controls according to the heights of your navbar and audio player.

The key is to set the maximum height and enable scrolling specifically within the div my-div, which prevents the entire app from scrolling unnecessarily.

By restricting the router functionality to this div, you can effectively manage the positioning of the audio player as well.

If the initial suggestion does not yield the desired result, try placing both the audio-player and my-div within a larger div that spans the full screen and contains all other elements. Make sure to apply appropriate styling.

Another approach could involve setting the body's CSS to scroll: none, and then implementing scroll functionalities within specific divs when required.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

CSS3 problem with using transparent PNGs as border images

Currently, I am implementing the border-image property using a PNG image that contains a transparent section. The issue arises when the background-color of the div is set to black. Upon applying the border-radius, the transparent section of the pattern dis ...

Maintain the selected image

I am working on a program that allows users to choose images and I have given them the pseudo-class. .my_image_class:hover{ border:3px solid blue; -webkit-box-sizing: border-box; } This makes the images bordered in blue when hovered over, giving a "sele ...

What could be the source of this margin or spacing?

Within this test, I have noticed that there are 2 inline flex containers. Specifically, I am referring to the test scenario that states Next The flex containers are laid out inline. Despite the fact that there is some space between the containers, upon in ...

FadeOut/FadeIn Iframe Animation

Help needed with making an iframe fade in and out using jQuery. Something seems off with the code and I can't figure out why it's not working. Can anyone spot the mistake? HTML <body> <center> <div class="headbackground" ...

iPhone 5 Internet Browser - charcoal matte .png with transparent background

When it comes to web design, I often rely on 24-bit transparent .png files. Recently, I was reviewing a website on an iPhone 5 and noticed that all my .png files had a black matte around them. However, when I checked the same website on an iPhone 4, everyt ...

Dynamic header that adjusts to fit window size fluctuations

I'm currently working on a website and trying to make it responsive by adjusting to changes in the browser window size. I'm having trouble changing the header height based on the window size unlike how it works for my pictures in CSS: #l ...

Should the username be specified but the password left blank, then an error message will be shown

<div class="form"> <h1>Sign In</h1> <form action="" method="post" name="login"> <input type="text" name="username" placeholder="Enter username" required /> <input type="password" name="password" placeholder="Enter password" ...

Struggling to add a border to an HTML div element

I'm completely baffled as to why I can't seem to add a border around my div. Here is the link to my jsfiddle: http://jsfiddle.net/4HnKs/1/ It's possible that I've been staring at my computer screen for too long, but no matter how hard ...

CSS: Create a form with two input fields where the left field is adjustable in width and the right field fills up

------------- -------------------------------------------------- | some unique text | | some more original content, varying length | ------------- -------------------------------------------------- |<---------------------- 100% width ------------------ ...

Steps for showing personalized validation error messages in Angular 7

Is there a way to highlight the input field of a form with a red border and display the message Password is invalid when a user types in a password that does not match the set password? I have managed to see the red border indicating an error when I enter ...

The background-image property fails to display on a table element

I’m having trouble displaying a background image in a table within my Django app. Here’s the code I’m using: <table style="background-image: url('/static/assets/img/myimage.png') ;background-position: 0 100% !important;background-repeat ...

Combining days and months in a date time using PHP

I am looking to create a textBox where users can input a date and time, followed by selecting an option from a dropdown menu that triggers a calculation. For instance: if ($exampleMonth === 11 && $exampleDay > 30) { $exampleMonth = 12; ...

Tips for effectively handling projects that call for varying versions of TypeScript within Visual Studio

In some cases, developers have had to downgrade their TypeScript version in order for it to work with a specific npm package version. Is it possible to do this with Visual Studio? I recently obtained a sample solution that utilized the angular2 npm packag ...

What is the process of creating an additional coding workspace within Visual Studio Code?

I have been attempting to incorporate an about.html page into my website, but when I click the link nothing occurs. My goal is to connect it to a different workspace. Despite already completing the js and CSS aspects, the hyperlink for this about page re ...

Using Linux to send beautifully formatted HTML emails

I am currently working on a Python 2.2 script that generates an HTML string by adding various elements to it. Here is a snippet of the code: html_string = "" html_string = html_string + "MIME-Version: 1.0\n" html_string = html_string + "Content-type: ...

Ensure the left and right screen widgets remain fixed in their positions as the user scrolls down the page using the spacebar

Currently, I have a webpage that showcases products with a large height attribute. I am looking for a way to make the page scroll down when the user hits the space bar to view more products. However, I want my screen widgets such as the shopping cart and ...

jQuery does not have the capability to access the href attribute through DOM manipulation

I've been trying to extract the href attribute from a link in my code and create a new link using that attribute. However, I'm facing an issue where the created link doesn't seem to work properly - it keeps showing a 404 error message like t ...

ClickEvent (or element selector) is experiencing functionality issues

I'm currently working on creating a small calculator using HTML, CSS, and JS. However, I'm facing an issue with selecting buttons of the calculator from the HTML script and adding EventListeners to them. Here is a snippet of my HTML code: `< ...

Div scrolling allows for parallel viewing of PDFs in a side by side arrangement

I have two scrollable elements on my webpage: one positioned on the left side and the other on the right side. The left element is a regular div, while the right element is an object containing an embedded PDF. <object width="100%" height=&quo ...

New feature: Mat select placeholder color change without needing required field validation

When the page initially loads, all controls (such as city, state, etc.) have white text color as shown in Image 1. I want to change the text color to red for all controls upon loading the page, resulting in a look similar to the image below. In the sectio ...