Twitter Bootstrap标签颠倒

时间:2013-06-06 11:31:18

标签: javascript twitter-bootstrap tabs

我使用了Twitter Bootstrap(http://twitter.github.io/bootstrap/javascript.html#tabs)标签功能,但我希望它是颠倒的,内容显示在顶部,TabMenuNav显示在底部! 这可能吗? 任何解决方法?

3 个答案:

答案 0 :(得分:13)

使用以下CSS获取您的预期。我向.tab-content类添加了边框以突出显示内容。

.tab-content {
padding:10px;
border:1px solid #ddd;
border-bottom:0px;
}
.nav-tabs {
border-bottom: 0px;
border-top: 1px solid #ddd;
}
.nav-tabs > li {
margin-bottom:0;
margin-top:-1px;
}

.nav-tabs > li > a {
padding-top: 8px;
padding-bottom: 8px;
line-height: 20px;
border: 1px solid transparent;
-moz-border-radius:0px;
-webkit-border-radius:0px;
border-radius:0px;
-moz-border-radius-bottomright: 5px;
-webkit-border-bottom-right-radius: 5px;
border-bottom-right-radius: 5px;
-moz-border-radius-bottomleft: 5px;
-webkit-border-bottom-left-radius: 5px;
border-bottom-left-radius: 5px;
}
.nav-tabs > .active > a, .nav-tabs > .active > a:hover, .nav-tabs > .active > a:focus {
color: #555555;
cursor: default;
background-color: #ffffff;
border: 1px solid #ddd;
border-top-color: transparent;
}

HTML结构应该是这样的:

<div class="tabbable">
    <div class="tab-content">
        <div id="tab1" class="tab-pane active">
            tab1 content</div>
        <div id="tab2" class="tab-pane">
            tab2 content</div>
        <div id="tab3" class="tab-pane">
            tab3 content</div>
        <div id="tab4" class="tab-pane">
            tab4 content</div>
    </div>
    <ul class="nav nav-tabs">
        <li class="active"><a href="#tab1" data-toggle="tab">tab1</a></li>
        <li><a href="#tab2" data-toggle="tab">tab2</a></li>
        <li><a href="#tab3" data-toggle="tab">tab3</a></li>
        <li><a href="#tab4" data-toggle="tab">tab4</a></li>
    </ul>
</div>

Bootply示例。

答案 1 :(得分:2)

对于那些正在寻找Bootstrap 4解决方案的人来说。

Bootstrap以前具有tabs-below类来实现此目的。但这是removed in version 3

我在以下代码中“恢复”了此功能。您只需将tabs-below类添加到ul元素中。检查https://jsfiddle.net/oniltonmaciel/nhfrz2bc/以获得完整的解决方案。

css:

.tabs-below {
  border-bottom-width: 0px;
  border-top: 1px solid #dee2e6;
}

.tabs-below .nav-link {
    border: 1px solid transparent;
    border-top-left-radius: 0px;
    border-top-right-radius: 0px;
    border-bottom-left-radius: .25rem;
    border-bottom-right-radius: .25rem;
}

.tabs-below .nav-item {
  margin-bottom: 0px;
  margin-top: -1px;
}

.tabs-below .nav-item.show .nav-link, .tabs-below .nav-link.active {
  border-color: #fff #dee2e6 #dee2e6  #dee2e6;
}

html:

  <div class="tab-content" id="myTabContent">
    <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab"><p>Contents of tab 1</p></div>
    <div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab"><p>Contents of tab 2</p></div>
    <div class="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab"><p>Contents of tab 3</p></div>
  </div>
  <ul class="nav nav-tabs tabs-below" id="myTab" role="tablist">
    <li class="nav-item">
      <a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">Home</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" id="profile-tab" data-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">Profile</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" id="contact-tab" data-toggle="tab" href="#contact" role="tab" aria-controls="contact" aria-selected="false">Contact</a>
    </li>
  </ul>

答案 2 :(得分:1)

尝试颠倒顺序,首先是<div class="tab-content">,最后是<ul class="nav nav-tabs" id="myTab">

<div class="tab-content">
  <div class="tab-pane active" id="home">...</div>
  <div class="tab-pane" id="profile">...</div>
  <div class="tab-pane" id="messages">...</div>
  <div class="tab-pane" id="settings">...</div>
</div>

<ul class="nav nav-tabs" id="myTab">
  <li class="active"><a href="#home">Home</a></li>
  <li><a href="#profile">Profile</a></li>
  <li><a href="#messages">Messages</a></li>
  <li><a href="#settings">Settings</a></li>
</ul>