简体   繁体   English

角材料2个带有固定(粘性)标签的标签

[英]Angular Material 2 Tabs with fixed (sticky) tab labels

I have a layout using Angular Material 2 mat-sidenav layout with a mat-tab layout in the mat-sidenav-content section. 我有一个使用Angular Material 2 mat-sidenav布局和mat-sidenav-content部分中的mat-tab布局的布局。 I am trying to make the mat-tab-labels sticky so they are always visible, and still allow the dynamic tab-content to scroll. 我正在尝试使mat-tab-labels粘性,以便它们始终可见,并且仍然允许动态tab-content滚动。 I can get the labels to stay fixed by setting overflow: hidden on the mat-sidenav-content and then set overflow: scroll on the mat-tab-body-wrapper element, but I have to set a fixed height to get the tab-content to scroll, but I have dynamic content so a fixed height isn't an option. 我可以通过设置overflow: hiddenmat-sidenav-content ,然后设置overflow: scrollmat-tab-body-wrapper元素上overflow: scroll来使标签保持固定,但是我必须设置固定高度才能获得tab-content要滚动的tab-content ,但是我有动态内容,因此不能选择固定高度。 Is there a way I can get my sticky labels and scrolling too without setting a fixed height? 有没有办法在我不设置固定高度的情况下获取粘性标签并滚动呢?

Below is a demo. 下面是一个演示。 Shrink the vertical height of your window until it covers part of the "Large content" div. 缩小窗口的垂直高度,直到它覆盖“大内容” div的一部分。 It will not scroll. 它不会滚动。 Then uncomment the mat-tab-group css that sets a height and it will scroll as desired (but a fixed height). 然后取消注释设置高度的mat-tab-group css,它将根据需要滚动(但固定高度)。

https://stackblitz.com/edit/angular-rty6oe?file=app%2Fsidenav-fixed-example.css https://stackblitz.com/edit/angular-rty6oe?file=app%2Fsidenav-fixed-example.css

UPDATE UPDATE

Ok, @Dakota Maker's answer solved the immediate problem, and also reminded me of what I was originally trying to fix that brought me to the point of not being able to scroll. 好的,@ Dakota Maker的答案解决了眼前的问题,也使我想起了我最初试图解决的问题,使我无法滚动。 I updated my example app to reflect my real app better. 我更新了示例应用程序,以更好地反映我的真实应用程序。 I have a sub-header inside the sidenav-content area that sits above the mat-tab-group, and when scrolling it never gets to the bottom unless the window height is large enough because the header seems to have pushed the content down and off the screen. 我在mata-tab-group上方的sidenav-content区域内有一个子标题,滚动时它永远不会到达底部,除非窗口高度足够大,因为标题似乎已经上下推了该内容屏幕。 I can add a margin to the bottom of the content to compensate for the sub-header, but the sub-header area height can change. 我可以在内容的底部添加一个边距以补偿子标题,但是子标题区域的高度可以更改。

If I should accept the answer to the original question and open a new question, please advise. 如果我应该接受原始问题的答案并打开一个新问题,请提出建议。

Set height:100% one the mat-tab-groups and you will be able to scroll and there won't be a big white block in the middle of the large content 设置height:100%一个mat-tab-groups ,您将可以滚动,并且大内容中间不会有大的白色块

EDIT TO ACCOMPANY OP's UPDATE: 编辑伴随OP的更新:

You can add something like bottom:12px to the .mat-tab-body-wrapper to give it a fixed amount of space at the bottom. 您可以在.mat-tab-body-wrapper添加诸如bottom:12px以在bottom:12px提供固定的空间。 This will end up giving you some of the overflow at the top of the wrapper some overlap with where the tabs are at, but you should be able to work that out also adding in something like margin-top:12px to the same block. 这最终将使您在包装器顶部的一些溢出与选项卡所在的位置重叠,但是您应该能够解决此问题,并在同一块中添加margin-top:12px之类的内容。 Hope this helps out! 希望这会有所帮助!

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

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