Locking MdToolbar within MdSidenavLayout

I am currently working on an Angular 2 Material application that incorporates the <md-sidenav-layout> with an <md-toolbar> nested inside.

<md-sidenav-layout>
  <md-sidenav #sidenav mode="side" class="app-sidenav" opened="true">
    sidenav content
  </md-sidenav>

  <md-toolbar color="primary" class="toolbar">
    toolbar content
  </md-toolbar>
</md-sidenav-layout>

The current layout appears as depicted in this image:

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

My objective is to ensure the toolbar remains fixed at the top, unaffected by scrolling. This consistency with the sidenav and its title is crucial. However, my attempts so far have been unsuccessful.

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

Initially, I considered using position: fixed; top: 0 to achieve this, but it did not yield the desired result:

/* Doesn't work */
.toolbar {
  position: fixed;
  top: 0;
}

Based on information from MDN: position and this Stack Overflow post regarding position: fixed, it appears that it may not function properly when the parent element utilizes a transform. The md-sidenav-layout likely employs this for transitions when toggling the sidenav. Testing position: fixed; top: 0 on a standalone page provided the expected outcome.

While removing the toolbar from the md-sidenav-layout context could be an option, doing so would compromise the animation and transition effects that ensure visual coherence between the toolbar and sidenav during toggling.

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

As my expertise in CSS is limited, I welcome any suggestions or workarounds to resolve this issue and achieve the desired effect.

For reference, here is the Plunker.

Answer №1

It's a good idea to place the content scroll inside the actual content itself. Personally, I always follow this practice when dealing with layouts that require scrolling because it feels more intuitive to have the scrollbar within the content area. For instance, if the sidebar content grows too large, it should have its own scrolling mechanism.

I'm not entirely sure why the material team chose to implement it differently, but hopefully having a fixed toolbar will be the default behavior in the final version, especially when using it with a sidenav layout (or at least there will be an option for it).

With that said, I've made some updates to your plunker to demonstrate my point: http://plnkr.co/edit/YViydOX9msbd8GJCGcm7?p=preview

The first step is to disable scrolling on the sidenav content:

/*
 * The /deep/ selector is used to bypass view encapsulation rules
 * and target the div.md-sidenav-content created dynamically
*/
md-sidenav-layout /deep/ .md-sidenav-content {
  overflow: hidden;
}

Then, ensure that .app-content fills the correct height and set its overflow property to auto:

.app-content {
  padding: 20px;
  height: calc(100% - 64px);
  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

Eliminate the hashtag (#) from the URL in Angular 11

I am facing an issue with removing the # from the URL. When I try to remove it, the application encounters a problem upon deployment to the server. Upon page refresh, a 404 error status is returned. For instance: https://example.com/user/1 (works) https ...

Is it possible to relocate an iframe outside the body of a post in Blogger?

For my blog posts, I have a goal of relocating the first iframe used outside of the post body and into a custom div called #myvideos. Some blog templates, such as this example, have already achieved this by moving a video out of the post body. I would like ...

Determining if a number exceeds 3 decimal points using AngularJS

I have encountered a problem where I need to determine if a value has more than three decimal places in AngularJS. Although I am familiar with checking if a value is a whole number or greater than zero, I am unsure how to perform this specific task. Below ...

The color of the button does not change when the jQuery onclick event is triggered

I am facing an issue with my buttons, specifically with Button 2. When Button 2 is clicked, I want the background color to change using an onclick event. However, despite my efforts, I have been unable to achieve this. Whenever I click Button 2, the colo ...

Is it not possible to change node labels in D3.js after clicking on a node?

After being inspired by this link, I successfully created a basic network visualization app using D3.js. The app reads node names from a textarea on an HTML page and then constructs a network where all nodes are interconnected. All the relevant code can ...

Hide the navigation menu when a page link is selected

Within my Angular 8 application, a fixed navigation bar is positioned at the top of the screen. Upon hovering over a dropdown nav link, a menu will appear for the user to explore. However, when a user clicks on one of these menu links, Angular Routing is ...

The Bootstrap nav-link class functions perfectly in Firefox, smoothly guiding users to the appropriate section. However, it seems to be experiencing some issues

I am currently working on customizing a one-page web template and I don't have much experience with Bootstrap. The template can be found at . My issue is that the menu items are not functional in Chrome. When I click on any menu item, nothing happens ...

How can a div be positioned outside of an overflow scroll without resorting to absolute positioning?

I am currently designing a blog theme and I would like to include a small box that displays the post date offset to the left of each post, similar to this mockup: My issue arises because the post container has overflow scrolling enabled, making it difficu ...

Adding Php code to a Wordpress form can be done by creating a custom

I'm struggling to incorporate a PHP code into a WordPress form that I created. Despite trying three different PHP plugins, I haven't been successful. Can anyone advise on where and how to properly integrate the PHP code in WordPress and call it t ...

Angular mistakenly uses the incorrect router-outlet

Encountering an issue with Angular routing. The main app has its own routing module, and there is a sub module with its own routing module and router-outlet. However, the routes defined in the submodule are being displayed using the root router outlet inst ...

What steps do I need to take to design a menu?

I need assistance in organizing my menu with submenus. The code I currently have successfully retrieves all the submenus, but I would like to categorize them accordingly: For instance: Main Menu - Submenu 1, Submenu 2, Submenu 3 How can I go about categ ...

Move the vertex onto the mxGraph canvas using drag-and-drop functionality

Hey there, I'm currently working on dragging and dropping a vertex from the create button onto the mxGraph canvas, similar to how it's done in draw.io. This is what my TS code looks like: addShape(shape: string,event) { event.stopPropagation(); ...

Behind every radio button lies a vertical line

Among a set of 7 radio buttons, I am looking to highlight the one in the center (id=q1val6) with a short vertical line running behind it to signify the zero point on a likert scale. <form name="form1" action="#" onsubmit="jsPsych.finishTrial()" method= ...

Searching for a specific element using Python and Selenium

Is there a way to locate an element using Selenium even if the XPath changes occasionally? Here is the code snippet: <input type="submit" value="Convert"> ...

Issue with concealing floated elements within a container div

I am currently facing an issue with trying to hide floated divs within a parent div, but unfortunately my code is not working as expected. Here is the code snippet: div.scrollarea { overflow: scroll; width: 400px; ...

Having trouble accurately obtaining the height of a DIV element using jQuery

After trying to troubleshoot on my own, I ran into a roadblock due to my specific requirements not being met by existing solutions. The issue at hand is as follows: I have a sticky DIV element positioned to the left, nested within another DIV Element wit ...

Tips for implementing [disabled] directive with dual options in Ionic Angular

Check out my page.html code: <ion-content *ngIf="charged"> Order ID: {{order.id_acg}} Item Weight(g): Height(cm): Width(cm): Length(cm): ...

Content within a div that is floated left

The scenario at hand is: HTML Structure: <div id="main"> <div id="a"></div> <div id="b">Some Text</div> </div> CSS Styles: #a{ float:left; width:800px; height:150px; background-color:#CCC; } ...

I can't seem to get my SCSS files to load properly on GitHub HTML pages, and I

Just starting out in the world of programming and decided to showcase my portfolio site on GitHub. While my index page is displaying correctly, I'm encountering issues with some images and all of my SCSS files not showing up. Any assistance or guidanc ...

Arrange the divs vertically by utilizing flexbox styling

My goal is to use flexbox to vertically align three div blocks. Even though I can successfully align them horizontally, I am facing issues with vertical alignment. What could be the mistake in my approach? .banner { padding- ...