Scrollbar is always visible on Angular Flex Layout

As someone who is just starting to work with Angular and flex layout, I have a simple page setup consisting of a header with a side navbar and router outlet.

I encountered an issue where my page always displays a scrollbar.

If I remove fxFlexFill, the scrollbar disappears. How can I resolve this problem?

You can check out a demo on Stackblitz here

Below is the template code:

.fill-space {
  flex: 1 1 auto;
}

.content {
  flex: 1 1 auto;
  padding: 15px;
  position: relative;
  overflow-y: auto;
}

.footer {
  display: flex;
  flex: 1 0 auto;
  justify-content: center;
}
<div style="height: 100vh;">
  <mat-toolbar color="primary" class="fixed-header">
    <mat-toolbar-row>
      <button mat-icon-button (click)="sidenav.toggle()" fxShow="true" fxHide.gt-sm>
        <mat-icon>menu</mat-icon>
      </button>
      <span><button mat-button routerLink="/home"><h3>HOSPITALITY</h3></button></span>
      <span class="fill-space"></span>
      <div fxShow="true" fxHide.lt-md="true">
        <button mat-button routerLink="/home">HOME</button>
        <button mat-button routerLink="/account">MY ACCOUNT</button>
        <button mat-button routerLink="/login">LOGOUT</button>

        <a href="#" routerLink="/cart" mat-button>
          <mat-icon>shopping_cart</mat-icon>
          0
        </a>
      </div>
    </mat-toolbar-row>
  </mat-toolbar>

  <mat-sidenav-container fxFlexFill>
    <mat-sidenav #sidenav fxLayout="column" mode="over"  opened="false" fxHide.gt-sm="true">
      
      <div fxLayout="column">
        <button mat-button routerLink="/home">HOME</button>
        <button mat-button routerLink="/account">MY ACCOUNT</button>
        <button mat-button routerLink="/login">LOGOUT</button>


        <a href="#" routerLink="/cart" mat-button>
          <mat-icon>shopping_cart</mat-icon>
          0
        </a>
      <a (click)="sidenav.toggle()" mat-list-item>
        <mat-icon>close</mat-icon> Close
      </a>
      </div>
    </mat-sidenav>
    <mat-sidenav-content >
      <div class="content">
        <router-outlet></router-outlet>
      </div>
    </mat-sidenav-content>
  </mat-sidenav-container>

</div>

Answer №1

The primary issue lies in the side navigation bar receiving a height of 100vh through the fxFlexFill directive.

To resolve this, it is important to consider the height of mat-toolbar-row, which can be achieved using CSS calc or other methods depending on the layout structure of the page.

Furthermore, there is an 8px margin applied to the body by default in browser styles.

Check out this version on StackBlitz for more information.

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

Guide to creating a smooth div fade transition with jquery on hover or mouseover

I have a div that is initially set to display:hidden. I am looking to change the display property to display:block when a specific element (#navbar li a) is hovered over. Below is the JavaScript code I have written for this functionality. $('document ...

Improperly shown on Internet Explorer

When I added a jQuery content slider to my website, it displayed incorrectly in Internet Explorer, showing a distorted header as well. The screenshot below illustrates the issue: Here is the code for my webpage: <%@ Page Language="C#" AutoEve ...

Issue with Firefox causing Bootstrap form to appear incorrectly

I recently created a customized form using Bootstrap, but unfortunately, I'm encountering an issue with Firefox. Despite functioning perfectly on other browsers, the radio buttons are being pushed off the edge of the page and aren't displaying pr ...

Angular 2 issue with nested form elements

Looking to build a form that includes nested sub/child components within it. Referring to this tutorial: https://scotch.io/tutorials/how-to-build-nested-model-driven-forms-in-angular-2 https://plnkr.co/edit/clTbNP7MHBbBbrUp20vr?p=info List of modificatio ...

Error in Angular 2: Module 'angular2/core' not found

I seem to be encountering an issue with Angular 2 and Typescript. Every time I attempt to gulp build, I keep getting the same errors. I've tried numerous solutions, including adding the <reference> tags in the files. Any suggestions on what step ...

Keeping the Angular Material sidenav constantly expanded on desktop screens

I just started learning Angular and I'm attempting to implement the sidenar component from Angular Material (current version). Here is the code snippet inside the main-nav component: <mat-sidenav-container class="sidenav-container" autosize> ...

Implementing Angular2 with Router in a Docker Container with Nginx Deployment

I am facing a challenge with deploying my Angular 2 application that utilizes the router capabilities of the framework while serving it with nginx inside a docker container. The file structure of the angular app created by angular-cli looks like this: ./ ...

Build upon a class found in an AngularJS 2 library

Whenever I attempt to inherit from a class that is part of a library built on https://github.com/jhades/angular2-library-example For example, the class in the library: export class Stuff { foo: string = "BAR"; } And the class in my application: exp ...

Understanding how to interpret error messages received from a server within an Angular component

Below is the code I am using for my backend: if (err) { res.status(400).send({ error: "invalid credentials", data: null, message: "Invalid Credentials" }); } else { res.status ...

Troubleshooting problems with forms using Bootstrap and HTML

I could use some assistance with a problem I'm facing while trying to acquire new skills through learning. I would like my picture and forms to resemble the one in this image: enter image description here index.html <div class="jumbotron"> &l ...

Tips on aligning a form element with another element in a Bootstrap column

Is there a more efficient way to position a globe glyph directly to the right of a textbox in multiple places throughout my code, almost touching it? One possible solution is as follows: <div class="col-md-3"> <input class="form-control" ...

Utilizing checkboxes for toggling the visibility of buttons in Angular

I want to dynamically show or hide buttons based on a checkbox. Here is the HTML code I am using: <input class="form-check-input" [(ngModel)]="switchCase" type="checkbox" id="flexSwitchCheckChecked" (change)=" ...

Tips for preventing the newly updated value from being linked to another array within Angular 13

Currently, I am using angular13 and working on a functionality where there is a button to move items from the left side to the right side. Interestingly, when an item is moved from the left to the right side and then edited under the right side, the edited ...

What is the best way to ensure that the content fits within a div with a given max-width set by the parent div?

image description goes here I have a container set to a maximum width of 80%, but when the text inside extends beyond that, the container remains stuck at 80% instead of adjusting its size accordingly. Can anyone provide a solution for this issue? ...

Ways to make two blocks of text appear side by side and adapt to different screen sizes

Check out our website imageI'm facing a challenge in making these two text elements appear next to each other rather than stacking on top of each other. Additionally, I need them to adapt responsively to changes in screen size. When 'Icontext&ap ...

Issue with Bootstrap 5.2 carousel not toggling the visually-hidden class

The hitboxes of the previous and next buttons are visually hidden. Additionally, the indicators at the bottom appear strange, and the sliding animation is not as smooth as expected. Despite searching extensively and trying various solutions, I am still un ...

How can a component be concealed in Angular while still permitting the passage of a function from the parent component?

Looking for a solution here: <app-csv-confirm-dialog *ngIf="false" (confirmUpload)="addDataFromCSV()"></app-csv-confirm-dialog> addDataFromCSV() { console.log('hi'); } In the TypeScript file for csv-confirm-dialog, I have this co ...

Adjust the size of the buttons based on the width of the screen

I have successfully implemented a dropdown menu with both text and an icon. However, I am now faced with the challenge of removing the text while retaining the icon when the screen width is reduced to a maximum of 768px. Is it possible to modify the conten ...

How to toggle elements using CSS slide animations?

Is there a way to make a div slide in and out from the left to right when the user clicks on "clickthis"? Here is an example of CSS code: .container{width:100px; position:absolute; left:-70px;} .container .open{left:0px;} .button{display:block; top:0px; ...

Steps for customizing a button's look

After installing the MemberPress plugin, I noticed that when I add my custom class, the "Login" button does not change. How can I rectify this issue and ensure that everything functions correctly? Original code <div class="submit"> <input t ...