Troubleshooting Double Scrollbar Issue in Angular Material Design Page Footer

I've implemented a page footer in the following way.

HTML

<footer class="app-footer-main">
  <section class="app-footer-items">
    ...
  </section>
</footer>

Styles

.app-footer-main {
  background-color: black;
}

.app-footer-items {
  position: relative;
  display: flex;
  font-size: small;
  justify-content: center;
}

I would like this footer to be positioned at the bottom of each page within the application. If the content on the page is lengthy, I want to be able to scroll down and see the footer at the end of the page.

The HTML below renders the main content of the application with the embedded footer.

  <mat-sidenav-container fullscreen class="sidenav-container">
    <!-- Collapsible side content -->
    <mat-sidenav #sidenav [mode]="'side'" class="navbar" role="navigation">
      <mat-nav-list>
        ...
      </mat-nav-list>
    </mat-sidenav>
    <!-- End Collapsible side content -->
    <!-- Main Content Area -->
    <div class="main-content">
      <div class="mat-app-background">
        <!-- Routed view  -->
        <router-outlet></router-outlet>
      </div>
    </div>
    <!-- End Main Content Area -->
    <app-footer #footer></app-footer>
  </mat-sidenav-container>

Main content style:

.main-content {
    padding: {
        top: 0;
        left: 15px;
        right: 15px;
        bottom: 0;
    }
    @include breakpoint($narrow-devices) {
        padding: {
            left: 15px;
            right: 15px;
        }
    }
    height: 100%;
    overflow: auto;
}

:host ::ng-deep .mat-sidenav-container[fullscreen] {
    top: 55px;
    @include breakpoint($narrow-devices) {
        top: 64px;
    }
}

// :host /deep/ is used to allow styling child components when using emulated view encapsulation.
:host ::ng-deep .mat-sidenav-content {
  transform: none !important;
}

.main-content {
    & ::ng-deep .outlet,
    & ::ng-deep .maxed-width {
        @include breakpoint($narrow-devices) {
                max-width: $page-max-width;
                margin: {
                    left: auto;
                    right: auto;
                }
        }
    }
}

.sidenav-container {
  flex: 1;
}

The issue with this setup is that there are two scrollbars on the page, as shown in the screenshot linked below. One scrollbar is for the main content area and the other is for the footer. How can I resolve this problem?

https://i.sstatic.net/A1WPx.png

Answer №1

Dealing with a similar issue recently, I found success with the following code solution: Setting the margin-top to be equal to the height of the footer proved effective for me. Instead of using '%' for height in the main div and footer, I opted for 'vh' and that resolved the problem.

.footer {
  position: relative;
  width: 100%;
  height: 20vh;
  margin-top: 20vh;
  margin-left: auto;
  margin-right: auto;
  bottom: 0;
  overflow: hidden;
}

Answer №2

After some adjustments, I was able to fix the issue by modifying the structure of the HTML code like this:

<mat-sidenav-container fullscreen class="sidenav-container">
    <!-- Collapsible side content -->
    <mat-sidenav #sidenav [mode]="'side'" class="navbar" role="navigation">
      <mat-nav-list>
        ...
      </mat-nav-list>
    </mat-sidenav>
    <!-- End Collapsible side content -->
    <mat-sidenav-content>
        <!-- Main Content Area -->
        <div class="main-content">
          <div class="mat-app-background">
            <!-- Routed view  -->
            <router-outlet></router-outlet>
          </div>
        </div>
        <!-- End Main Content Area -->
        <app-footer #footer></app-footer>
    </mat-sidenav-content>
  </mat-sidenav-container>

To address the issue, update the height property of the main-content CSS class to use min-height instead:

.main-content {
    padding: {
        top: 0;
        left: 15px;
        right: 15px;
        bottom: 0;
    }
    @include breakpoint($narrow-devices) {
        padding: {
            left: 15px;
            right: 15px;
        }
    }
    min-height: 100%;
    overflow: auto;
}

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

The window.Print() function is currently experiencing a glitch in Microsoft Edge (Version 91.0.864.59) when trying to use it for the first time within an Angular 12

If you encounter the issue, please follow these steps using the latest version 91.0.864.59 of the Edge browser: https://stackblitz.com/edit/angular-ivy-zbvzap?file=src/app/app.component.html Click on the print button. Close the print dialog. Click on the ...

"Exploring AngularFire Database: Simple ways to retrieve the total number of items in a list

I attempted to utilize angularfire2 in order to develop a function that retrieves the total number of entries in a list within a firebase real-time database. For instance: Retrieve the count of users in '/users'. I am not interested in continuou ...

Is it possible for changes made to an object in a child component to be reflected in the parent component

When passing an object to the child component using , how can we ensure that changes made to a specific property in the object within the child component are visible in the parent component? In my understanding, changes would not be reflected if we were p ...

Tips for maintaining the select dropdown open while opening the mat-menu in Angular

I am working with a mat-select component that has custom options including an additional menu item "Set as default": <mat-form-field appearance="fill"> <mat-label>Favorite food</mat-label> <mat-select> <mat-opti ...

The JavaScript program for the shopping list is experiencing issues with the formatting of list items

I have been working on developing a shopping list program using JavaScript. The program includes an input box and an "add item" button, which adds the text entered in the input field to an unordered list as a list item. Each list item also contains an imag ...

Boost the dimensions of the content property within a CSS class

I am currently using the content property to display a dashed arrow "-->" in my CSS class. However, the arrow appears very small and I would like to increase its size directly in the CSS class itself. This arrow is meant to be displayed before each elem ...

preserve functionality when switching between pages

I have created two simple functions that can change the background color of the body. <script type="text/javascript"> function switchBackground(color){ document.body.bgColor=color; } </script> I am using links with onclick to execute thes ...

How to achieve striped columns with Bootstrap 4.0 instead of striped rows

Here is how my table currently looks with the implementation in place: https://i.sstatic.net/b7onC.png Since my data is displayed vertically, I am interested in adding stripes to the columns or implementing some CSS hovering effect when the mouse is over ...

Is your Angular 2 Observable malfunctioning?

sendMessage(message: string, recipient: string){ console.log(message, recipient, this.user); let newMessage = {from: this.user['name'], msg: message}; this.sub = this.route.params.subscribe( params => { let name = recipient ...

What is the alternative to using echo when outputting HTML?

I am working on a function... $post_text .= '<div style="font-size: 15px; color: blueviolet">'; $post_text .= "<br>"; $post_text .= 'Text number 1.'; $post_text .= "<br>"; $post_text .= 'Text number 2.'; $po ...

Tips for setting up a mdl-dialog using a declarative approach

I want to incorporate a mdl-dialog into my component following the example provided here: However, when I try to do so, the compiler throws an error stating: Can't bind to 'mdl-dialog-config' since it isn't a known property of ' ...

Incompatibility Issues Between CSS and WordPress Custom Menu Functionality

I'm having trouble getting a custom menu to work in my Wordpress theme. Although I've enabled the feature and added the menu to my layout successfully, the CSS styling for the menu doesn't seem to be applying. I initially had a custom CSS f ...

Refresh gif without having to reload it in Internet Explorer 11

I'm attempting to create a feature where a gif restarts when clicked by the user, without needing to reload it (due to the heavy size of the gif which is preloaded for my application). The current code functions flawlessly on Chrome and other "modern ...

Tips for displaying user data from a mongodb database on a webpage, making edits to the information, and then saving the updated data

I have a website where users can register, log in, and update their profile information. However, I am facing an issue where only the data of the first user in the database table is being retrieved. How can I get the data of the currently logged-in user? ...

The Npm audit inspection revealed a single low-risk vulnerability within the karma > expand-braces > braces component

The Npm audit report has flagged 'found 1 low severity vulnerability'. Manual review is needed for this vulnerability. Low Regular Expression Denial of Service Package braces Patched in >=2.3.1 Dependency of ...

How do I retrieve the top position of the text content itself, not the text element, using jQuery or Javascript?

I'm facing a unique challenge and need some guidance: I am trying to determine the exact y-coordinate of specific text in a document. Simply getting the y-coordinate of the container element is not sufficient for my needs. To illustrate this issue, p ...

Why am I struggling to show the success message on my basic CRM Angular web application?

I'm facing an issue in my Basic Angular app where the success message is not being displayed even after writing the correct code. 1)app.component.html <h1 class="c1">{{title}}</h1> <div *ngIf="success_msg;" style=&q ...

What is the best way to change the orientation of the Product List in WooCommerce to landscape

Is there a way to change our product list display to landscape orientation? The current portrait layout is not visually appealing due to excessive white space. I would greatly appreciate any guidance on how to resolve this issue. You can view our website ...

Firm emblem obstructs individual avatar

I have noticed a strange issue with my header layout. When I include the hamburger menu and user icon, they align perfectly in a row. However, as soon as I add the company logo, the user icon shifts downward and breaks the alignment. I have tried adjustin ...

Button click does not trigger component reload

Presented below is a button element that triggers the following action when clicked: <button mat-button (click)="toggleLikeQuestion(question['id'])" aria-label="Like this question."> {{!isQuestionLike ...