简体   繁体   English

仅为选项卡内容添加滚动,但不为 Clarity Tabs 中的选项卡标签添加滚动

[英]Add scroll only for a tab content but not for a tab label in Clarity Tabs

I have a tab with long content in the project (StackBlitz ref is here ).我在项目中有一个包含很长内容的选项卡(StackBlitz 参考在这里)。

So the scroll appears.于是出现了卷轴。

在此处输入图片说明

The corresponding code for it is它的对应代码是

<div class="content-container">
        <div class="content-area">

            <clr-tabs>
                <clr-tab>
                    <button clrTabLink id="tab1-link">Tab1</button>
                    <clr-tab-content id="tab1-content" *clrIfActive="true">
                        ...
                    </clr-tab-content>
                </clr-tab>
                <clr-tab>
                    <button clrTabLink id="tab2-link">Tab2</button>
                    <clr-tab-content id="tab2-content" *clrIfActive>
                        Content2
                    </clr-tab-content>
                </clr-tab>
            </clr-tabs>

        </div>
    </div>

The problem is that the scroll covers tab labels and tab content.问题是滚动覆盖了选项卡标签和选项卡内容。 But I need it to cover only tab content so the tab labels would stay if I scroll down.但我需要它只覆盖选项卡内容,因此如果我向下滚动,选项卡标签将保留。

I tried to add the following styles to fix it我尝试添加以下样式来修复它

.content-area {
  overflow: hidden !important;
  height: 100%;
}

#tab1-content, #tab2-content {
  height: 100%;
  overflow: auto;
}

But this resulted in scroll disappearing at all.但这导致滚动完全消失。 How can I add the scroll only for a tab content?如何仅为选项卡内容添加滚动?

I'm afraid I couldn't work out enough from your code snippet so looked at the code in Stackblitz.恐怕我无法从您的代码片段中得出足够的答案,因此查看了 Stackblitz 中的代码。 In that, Tab1 and Tab2 are list elements in an unordered list with class nav.其中,Tab1 和 Tab2 是具有类 nav 的无序列表中的列表元素。

Moving this nav ul out of the content-container div and putting it immediately below the header-2 header element gives you what I think you need, the content-container div fills up the remainder of the main container and scrolls with the Tab list elements remaining fixed above.将此导航移出内容容器 div 并立即将其放在 header-2 标题元素下方为您提供我认为您需要的内容,内容容器 div 填充了主容器的其余部分并随 Tab 列表元素滚动上面保持固定。

This may just be luck - in that all the required flex-related settings are already in place.这可能只是运气 - 因为所有必需的与 flex 相关的设置都已经到位。

I found the following solution.我找到了以下解决方案。 I need to add to parent component content-area which contains all tabs the overflow property.我需要将overflow属性添加到包含所有选项卡的父组件content-area

.content-area {
  overflow: hidden ;
}

It removes the current scrollbar.它删除当前滚动条。 After that we can found the height of above elements using Chrome Dev Tools.之后,我们可以使用 Chrome Dev Tools 找到上述元素的高度。

在此处输入图片说明

Now we should wrap the tab content into another div with some class (eg mytab-content ).现在我们应该用某个类(例如mytab-content )将选项卡内容包装到另一个 div 中。

    <clr-tab-content id="tab1-content" *clrIfActive="true">
        <div class="mytab-content">
        .......
        </div>
    </clr-tab-content>

And finally we should add the following styles for that class最后我们应该为该类添加以下样式

.mytab-content {
  height: calc(100vh - 60px - 36px);
  overflow: auto;
}

It will add scroll only for tab content.它只会为选项卡内容添加滚动。

在此处输入图片说明

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

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