[英]Bootstrap tab content goes down
I have a big problem with my Bootstrap tab-pane content.我的 Bootstrap 选项卡窗格内容有一个大问题。
<ul class="nav nav-pills nav-justified">
<li class="active"><a data-toggle="tab" href="#masery1">Mastery Page 1</a></li>
<li><a data-toggle="tab" href="#masery2">Mastery Page 2</a></li>
<li><a data-toggle="tab" href="#masery3">Mastery Page 3</a></li>
<li><a data-toggle="tab" href="#masery4">Mastery Page 4</a></li>
<li><a data-toggle="tab" href="#masery5">Mastery Page 5</a></li>
<li><a data-toggle="tab" href="#masery5">Mastery Page 6</a></li>
</ul>
<div id="masery1" class="tab-pane fade in active">
<h1>Show the last 10 Games</h1>
</div>
<div id="masery2" class="tab-pane fade ">
<h1>Show the last 10 Games</h1>
</div>
<div id="masery3" class="tab-pane fade">
<h1>Show the last 10 Games</h1>
</div>
<div id="masery4" class="tab-pane fade">
<h1>Show the last 10 Games</h1>
</div>
<div id="masery5" class="tab-pane fade">
<h1>Show the last 10 Games</h1>
</div>
The Content goes on every tab a bit more down.内容在每个选项卡上都向下一点。
So #mastery1 looks fine but #mastery2's content is 200px lower then #mastery1 etc etc.所以#mastery1 看起来不错,但#mastery2 的内容比#mastery1 等低 200px。
I don't understand why.我不明白为什么。 I check every <div>
.我检查每个<div>
。
You can see it here on the "Mastery Tab": https://lolstats.org/HORNETDanny/euw你可以在“精通选项卡”上看到它: https ://lolstats.org/HORNETDanny/euw
You're missing a div for your mastery tabs.您缺少用于掌握选项卡的 div。 Wrap the mastery divs in a new div using tab-content.使用 tab-content 将 mastery div 包裹在一个新的 div 中。
<div class="tab-content">
<div id="masery1" class="tab-pane fade in active">
<h1>Show the last 10 Games</h1>
</div>
<div id="masery2" class="tab-pane fade ">
<h1>Show the last 10 Games</h1>
</div>
<div id="masery3" class="tab-pane fade">
<h1>Show the last 10 Games</h1>
</div>
<div id="masery4" class="tab-pane fade">
<h1>Show the last 10 Games</h1>
</div>
<div id="masery5" class="tab-pane fade">
<h1>Show the last 10 Games</h1>
</div>
</div>
This applies the following CSS rule:这适用以下 CSS 规则:
.tab-content>.tab-pane {
display: none;
}
Since divs have height, each div was taking up space on the page.由于 div 具有高度,因此每个 div 都会占用页面上的空间。 Setting them to display: none
, gives them no height.将它们设置为display: none
,不给它们高度。 When a selected div has the active
css class, the following rule is applied overriding the display none
. When a selected div has the active
css class, the following rule is applied overriding the display none
.
.tab-content>.active {
display: block;
}
Try wrapping your divs for each tab (with class of tab-pane
) in a div
with class="tab-content"
such as:尝试将每个选项卡的 div(带有tab-pane
类)包装在一个带有class="tab-content"
的div
中,例如:
<div class="tab-content">
<div id="mastery1" class="tab-pane fade">
<h1>Show the last 10 Games</h1>
<div>
<!-- more tab content -->
</div>
See the Bootstrap document for tabs here: https://getbootstrap.com/javascript/#markup在此处查看选项卡的 Bootstrap 文档: https ://getbootstrap.com/javascript/#markup
Also it is worth noting that for some magic reason flex doesn't like tab-pane class so if you want to have flex conatiner inside tab you have to do this like:另外值得注意的是,出于某些神奇的原因,flex 不喜欢 tab-pane 类,所以如果你想在 tab 中有 flex conatiner,你必须这样做:
<div class="tab-pane fade" id="home" role="tabpanel" aria-labelledby="1-tab">
<div class="d-flex flex-row flex-wrap">
# something here
</div>
</div>
if you put d-flex in the same div as tab-pane content is hidden but it still takes space that's why it is moved down.如果您将 d-flex 放在同一个 div 中,因为选项卡窗格内容被隐藏,但它仍然占用空间,这就是它被向下移动的原因。
You are getting that abnormality because the first tab hides but still occupies the space it was occupying in the first place.您遇到这种异常是因为第一个选项卡隐藏了但仍然占据了它最初占据的空间。 The work around i did was to find a way to hide it whenever any of the other tabs is clicked and show it when it is clicked.我所做的工作是找到一种方法来在单击任何其他选项卡时隐藏它并在单击时显示它。
In your HTML add the [class] property to your tags like this在您的 HTML 中,将 [class] 属性添加到您的标签中,如下所示
<div id="masery1" class="tab-pane fade in active" [class]="hideFirst" >
<h1>Show the last 10 Games</h1>
</div>
Then add the click event to your tabs title like this然后像这样将点击事件添加到您的标签标题
<ul class="nav nav-pills nav-justified">
<li class="active" (onclick)="clickTab(1)"><a data-toggle="tab"
href="#masery1">Mastery Page 1</a></li>
<li (onclick)="clickTab(2)"><a data-toggle="tab" href="#masery2">Mastery Page 2</a>
</li>
<li (onclick)="clickTab(3)"><a data-toggle="tab" href="#masery3">Mastery Page 3</a>
</li>
<li (onclick)="clickTab(4)"><a data-toggle="tab" href="#masery4">Mastery Page 4</a>
</li>
<li (onclick)="clickTab(5)"><a data-toggle="tab" href="#masery5">Mastery Page 5</a>
</li>
<li (onclick)="clickTab(6)"><a data-toggle="tab" href="#masery5">Mastery Page 6</a>
</li>
</ul>
then in your typescript declare the variable as follows然后在你的打字稿中声明变量如下
hideFirst: string = "hide"
Also create the clickTab function as follows同样创建 clickTab 函数如下
clickTab(num){ this.hideFirst = num === 1? 'show': 'hide'; }
THis should do the trick...Happy coding:)这应该可以解决问题......编码愉快:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.