简体   繁体   English

如何制作粘性角材料垫工具栏?

[英]How to make a sticky Angular Material mat-toolbar?

I've been trying to implement a mat-toolbar that is located after the initial navigation bar and I can't seem to get it right.我一直在尝试实现一个位于初始导航栏之后的垫子工具栏,但我似乎无法正确使用。 I've tried adding the class "position-fixed."我试过添加“位置固定”类。

This would work if the initial position was at the top of the page but it is not.如果初始位置位于页面顶部,这将起作用,但事实并非如此。 Once the user scrolls past the toolbar, it should "stick" to the top of the page.一旦用户滚动通过工具栏,它应该“粘”到页面的顶部。

Any ideas how to implement this?任何想法如何实现这一点? I've tried combinations of我试过组合

.stickyBar { position: sticky; }

and the position-fixed but no luck.和位置固定但没有运气。

Any ideas?有任何想法吗? Thanks谢谢

There were parent elements with the css property overflow: hidden which interferes with position: sticky.有父元素的 css 属性溢出:隐藏干扰位置:粘性。 Here's the post used to solve my question.这是用于解决我的问题的帖子。

Make the change below:进行以下更改:

mat-toolbar{
  display: initial;
}
.stickyBar {
  position: sticky;
  top: 0;
}

As soon as you add the <mat-toolbar> parent with a particular height, the stickybar will only stay stuck for the size of the toolbar.一旦您添加具有特定高度的<mat-toolbar>父项,粘性栏将仅停留在工具栏的大小上。 In other-words, if you set the height of the toolbar to 10vh you will see that the sticky-bar stays stuck for the 10vh space.换句话说,如果您将工具栏的高度设置为 10vh,您将看到粘性栏在 10vh 的空间内保持卡住。 The reason is that the sticky-ness is only applied to the parent container's share of the viewport.原因是粘性仅应用于父容器的视口份额。 Workaround from: Why is my position:sticky not working?解决方法: 为什么我的 position:sticky 不起作用?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM