Foundation tab


Tab navigation can display different content very well and can switch content.

Tabs are created using <ul class="tabs" data-tab>, and each option uses the <li> element plus .tab-title class to create.

Tips: The currently selected item can use the .active class.

Instance

<!DOCTYPE html>
<html>
<head>
  <title>Foundation 实例</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://static.php.cn/assets/foundation-5.5.3/foundation.min.css">
  <script src="http://static.php.cn/assets/jquery/2.0.3/jquery.min.js"></script>
  <script src="http://static.php.cn/assets/foundation-5.5.3/js/foundation.min.js"></script>
  <script src="http://static.php.cn/assets/foundation-5.5.3/js/vendor/modernizr.js"></script>
</head>
<body style="padding:20px">

<h2>选项卡</h2>
<ul class="tabs" data-tab>
  <li class="tab-title active"><a href="#">Home</a></li>
  <li class="tab-title"><a href="#">Menu 1</a></li>
  <li class="tab-title"><a href="#">Menu 2</a></li>
  <li class="tab-title"><a href="#">Menu 3</a></li>
</ul>

</body>
</html>

Run Instance»

Click the "Run Instance" button to view the online instance


Vertical tab

Vertical tab can use .vertical Class:

Instance

<!DOCTYPE html>
<html>
<head>
  <title>Foundation 实例</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://static.php.cn/assets/foundation-5.5.3/foundation.min.css">
  <script src="http://static.php.cn/assets/jquery/2.0.3/jquery.min.js"></script>
  <script src="http://static.php.cn/assets/foundation-5.5.3/js/foundation.min.js"></script>
  <script src="http://static.php.cn/assets/foundation-5.5.3/js/vendor/modernizr.js"></script>
</head>
<body style="padding:20px">

<h2>垂直选项卡</h2>
<ul class="tabs vertical" data-tab>
  <li class="tab-title active"><a href="#">Home</a></li>
  <li class="tab-title"><a href="#">Menu 1</a></li>
  <li class="tab-title"><a href="#">Menu 2</a></li>
  <li class="tab-title"><a href="#">Menu 3</a></li>
</ul>

</body>
</html>

Run Instance»

Click the "Run Instance" button to view the online instance


Switch tab

If you want to set the switch For tags, you can use the <div> element plus the .content class. Add a unique ID to each tab and connect it to the list item (<a href="#menu1" will open the option content with id="menu1"). Finally, place all the option content on the <div> element. The <div> element needs to add the .tabs-content class and initialize Foundation. JS.

Note.active The class will be automatically added to the currently selected tab:

Instance

<!DOCTYPE html>
<html>
<head>
  <title>Foundation 实例</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://static.php.cn/assets/foundation-5.5.3/foundation.min.css">
  <script src="http://static.php.cn/assets/jquery/2.0.3/jquery.min.js"></script>
  <script src="http://static.php.cn/assets/foundation-5.5.3/js/foundation.min.js"></script>
  <script src="http://static.php.cn/assets/foundation-5.5.3/js/vendor/modernizr.js"></script>
</head>
<body style="padding:20px">

<h2>切换选项卡</h2>

<ul class="tabs" data-tab="">
  <li class="tab-title"><a href="#home" aria-selected="false" tabindex="-1">主页</a></li>
  <li class="tab-title"><a href="#menu1" aria-selected="false" tabindex="-1">菜单 1</a></li>
  <li class="tab-title active"><a href="#menu2" aria-selected="true" tabindex="0">菜单 2</a></li>
  <li class="tab-title"><a href="#menu3" aria-selected="false" tabindex="-1">菜单 3</a></li>
</ul>
<div class="tabs-content">
  <div class="content" id="home" aria-hidden="true" tabindex="-1">
    <h3>主页</h3>
    <p>主页内容..</p>
  </div>
  <div class="content" id="menu1" aria-hidden="true" tabindex="-1">
    <h3>菜单 1</h3>
    <p>一些文本内容 1</p>
  </div>
  <div class="content active" id="menu2" aria-hidden="false">
    <h3>菜单 2</h3>
    <p>一些文本内容 2</p>
  </div>
  <div class="content" id="menu3" aria-hidden="true" tabindex="-1">
    <h3>菜单 3</h3>
    <p>一些文本内容 3</p>
  </div>
</div>

<!--初始化 Foundation JS -->
<script>
$(document).ready(function() {
    $(document).foundation();
})
</script>

</body>
</html>

Run instance»

Click the "Run instance" button to view the online instance


Tab fade-in

Use CSS to customize the tab fade-in Effect:

Instance

<!DOCTYPE html>
<html>
<head>
  <title>Foundation 实例</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://static.php.cn/assets/foundation-5.5.3/foundation.min.css">
  <script src="http://static.php.cn/assets/jquery/2.0.3/jquery.min.js"></script>
  <script src="http://static.php.cn/assets/foundation-5.5.3/js/foundation.min.js"></script>
  <script src="http://static.php.cn/assets/foundation-5.5.3/js/vendor/modernizr.js"></script>
<style>
.tabs-content > .content.active {
    -webkit-animation: fadeEffect 1s;
    animation: fadeEffect 1s;
}

@-webkit-keyframes fadeEffect {
    from {opacity: 0;}
    to {opacity: 1;}
}

@keyframes fadeEffect {
    from {opacity: 0;}
    to {opacity: 1;}
}
</style>
</head>
<body style="padding:20px">

<h2>淡入切换选项卡</h2>
<ul class="tabs" data-tab>
  <li class="tab-title active"><a href="#home">主页</a></li>
  <li class="tab-title"><a href="#menu1">菜单 1</a></li>
  <li class="tab-title"><a href="#menu2">菜单 2</a></li>
  <li class="tab-title"><a href="#menu3">菜单 3</a></li>
</ul>
<div class="tabs-content">
  <div class="content active" id="home">
    <h3>HOME</h3>
    <p>首页内容。</p>
  </div>
  <div class="content" id="menu1">
    <h3>菜单 1</h3>
    <p>文本内容。</p>
  </div>
  <div class="content" id="menu2">
    <h3>菜单 2</h3>
    <p>文本内容。</p>
  </div>
  <div class="content" id="menu3">
    <h3>菜单 3</h3>
    <p>文本内容。</p>
  </div>
</div>

<!-- 初始化 Foundation JS -->
<script>
$(document).ready(function() {
    $(document).foundation();
})
</script>

</body>
</html>

Run instance»

Click the "Run instance" button to view the online instance