简体   繁体   中英

Twitter Bootstrap Tabs Upside Down

I have used Twitter Bootstrap ( http://twitter.github.io/bootstrap/javascript.html#tabs ) Tabs feature, but I want it to be upside down, with Content shown on the Top and the TabMenuNav at the bottom! Is this possible? Any workarounds?

Use the following CSS to get what you expected. I added border to .tab-content class to get the content highlighted.

.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;
}

The HTML structure should be like this:

<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>

For those arriving looking for a solution for Bootstrap 4.

Bootstrap used to have tabs-below class to achieve this. But it was removed in version 3 .

I "restored" this feature in the following code. You just need to add tabs-below class to your ul element. Check https://jsfiddle.net/oniltonmaciel/nhfrz2bc/ for the full solution.

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>

Try to invert the order, with the <div class="tab-content"> first and with <ul class="nav nav-tabs" id="myTab"> for last.

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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