Foundation top navigation bar
The top navigation bar is placed at the head of the page:
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> <nav class="top-bar" data-topbar> <ul class="title-area"> <li class="name"> <!-- 如果你不需要标题或图标可以删掉它 --> <h1><a href="#">WebSiteName</a></h1> </li> <!-- 小屏幕上折叠按钮: 去掉 .menu-icon 类,可以去除图标。 如果需要只显示图片,可以删除 "Menu" 文本 --> <li class="toggle-topbar menu-icon"><a href="#"><span>Menu</span></a></li> </ul> <section class="top-bar-section"> <ul class="left"> <li class="active"><a href="#">Home</a></li> <li><a href="#">Page 1</a></li> <li><a href="#">Page 2</a></li> <li><a href="#">Page 3</a></li> </ul> </section> </nav> <div style="padding:20px;"> <h3>基本头部工具条实例</h3> <p>工具条是在页面头部的导航。</p> <p><strong>注意:</strong> 在小屏幕上工具条会被一个按钮取代 (重置窗口,查看效果)。</p> <p>在按钮被点击后导航项将显示。</p> </div> <!-- 初始化 Foundation JS --> <script> $(document).ready(function() { $(document).foundation(); }) </script> </body> </html>
Run instance»
Click "Run" Example" button to view online examples
Example analysis
Use<nav class="top-bar" data-topbar>
to create a standard toolbar. The .title-area
class defines the website logo area (must avoid li.name
). After the screen becomes smaller you can see a "menu" button. Foundation's menu will automatically fold and expand according to the screen size:
On a small screen, many options will be hidden due to size. li.toggle-topbar menu.icon
Class creates a menu button that can be clicked to display hidden options.
Tips: Reset the browser window to see the effect.
.top-bar-section
Defines the link section of the navigation. .left
Class specifies that links are left aligned. .active
class is used to display the selected item with a blue background.
Tips: If you want the navigation link to be right-aligned, you can change .left
to .right
:
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> <nav class="top-bar" data-topbar> <ul class="title-area"> <li class="name"> <!-- 如果你不需要标题或图标可以删掉它 --> <h1><a href="#">WebSiteName</a></h1> </li> <!-- 小屏幕上折叠按钮: 去掉 .menu-icon 类,可以去除图标。 如果需要只显示图片,可以删除 "Menu" 文本 --> <li class="toggle-topbar menu-icon"><a href="#"><span>Menu</span></a></li> </ul> <section class="top-bar-section"> <ul class="right"> <li class="active"><a href="#">Home</a></li> <li><a href="#">Page 1</a></li> <li><a href="#">Page 2</a></li> <li><a href="#">Page 3</a></li> </ul> </section> </nav> <div style="padding:20px;"> <h3>右对齐工具条</h3> <p> .right 类设置工具条按钮右对齐。</p> <p><strong>注意:</strong> 在小屏幕上工具条会被一个按钮取代 (重置窗口,查看效果)。</p> <p>在按钮被点击后导航项将显示。</p> </div> <!-- Initialize Foundation JS --> <script> $(document).ready(function() { $(document).foundation(); }) </script> </body> </html>
Run instance»
Click the "Run instance" button to view the online instance
You can also set the left Align to the right:
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> <nav class="top-bar" data-topbar> <ul class="title-area"> <li class="name"> <h1><a href="#">WebSiteName</a></h1> </li> <!-- 小屏幕上折叠按钮: 去掉 .menu-icon 类,可以去除图标。 如果需要只显示图片,可以删除 "Menu" 文本 --> <li class="toggle-topbar menu-icon"><a href="#"><span>Menu</span></a></li> </ul> <section class="top-bar-section"> <ul class="left"> <li class="active"><a href="#">Home</a></li> <li><a href="#">Page 1</a></li> <li><a href="#">Page 2</a></li> </ul> <ul class="right"> <li><a href="#">Sign Up</a></li> <li><a href="#">Login</a></li> </ul> </section> </nav> <div style="padding:20px;"> <h3>左右都有对齐</h3> <p>该实例演示了工具条左右都有选项。</p> <p><strong>注意:</strong> 在小屏幕上工具条会被一个按钮取代 (重置窗口,查看效果)。</p> <p>在按钮被点击后导航项将显示。</p> </div> <!-- 初始化 Foundation JS --> <script> $(document).ready(function() { $(document).foundation(); }) </script> </body> </html>
Run Instance»
Click the "Run Instance" button to view the online instance
The navigation bar can add dividing lines through the .divider
class (vertical lines on large screens, horizontal lines on small screens):
Example
<!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> <nav class="top-bar" data-topbar> <ul class="title-area"> <li class="name"> <h1><a href="#">WebSiteName</a></h1> </li> <!-- 小屏幕上折叠按钮: 去掉 .menu-icon 类,可以去除图标。 如果需要只显示图片,可以删除 "Menu" 文本 --> <li class="toggle-topbar menu-icon"><a href="#"><span>Menu</span></a></li> </ul> <section class="top-bar-section"> <ul class="left"> <li class="active"><a href="#">Home</a></li> <li class="divider"></li> <li><a href="#">Page 1</a></li> <li class="divider"></li> <li><a href="#">Page 2</a></li> <li class="divider"></li> <li><a href="#">Page 3</a></li> <li class="divider"></li> </ul> </section> </nav> <div style="padding:20px;"> <h3>顶部导航栏分割线</h3> <p>导航栏可以通过 .divider 类来添加分割线 (大屏幕上是垂直的线,小屏幕上是水平线)。</p> </div> <!-- 初始化 Foundation JS --> <script> $(document).ready(function() { $(document).foundation(); }) </script> </body> </html>
Run instance»
Click the "Run instance" button to view the online instance
in the navigation bar Drop-down menu
The top navigation bar can set up a drop-down menu.
You can set up the drop-down menu by adding the .has-dropdown
class on the <li>
element:
Example
<!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> <nav class="top-bar" data-topbar> <ul class="title-area"> <li class="name"> <h1><a href="#">WebSiteName</a></h1> </li> <!-- 小屏幕上折叠按钮: 去掉 .menu-icon 类,可以去除图标。 如果需要只显示图片,可以删除 "Menu" 文本 --> <li class="toggle-topbar menu-icon"><a href="#"><span>Menu</span></a></li> </ul> <section class="top-bar-section"> <ul class="left"> <li class="active"><a href="#">Home</a></li> <li class="has-dropdown"> <a href="#">Dropdown</a> <ul class="dropdown"> <li><a href="#">First link in dropdown</a></li> <li><a href="#">Second link in dropdown</a></li> <li class="active"><a href="#">Active link in dropdown</a></li> </ul> </li> </ul> </section> </nav> <div style="padding:20px;"> <h3>带有下拉菜单的工具栏</h3> <p>该实例演示了带有下拉菜单的攻击栏。</p> </div> <!-- 初始化 Foundation JS --> <script> $(document).ready(function() { $(document).foundation(); }) </script> </body> </html>
Run instance»
Click the "Run instance" button to view the online instance
Separating line
Use .divider
Class to set the dividing line of the drop-down menu:
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> <nav class="top-bar" data-topbar> <ul class="title-area"> <li class="name"> <h1><a href="#">WebSiteName</a></h1> </li> <!-- 小屏幕上折叠按钮: 去掉 .menu-icon 类,可以去除图标。 如果需要只显示图片,可以删除 "Menu" 文本 --> <li class="toggle-topbar menu-icon"><a href="#"><span>Menu</span></a></li> </ul> <section class="top-bar-section"> <ul class="left"> <li class="active"><a href="#">Home</a></li> <li class="has-dropdown"> <a href="#">Dropdown</a> <ul class="dropdown"> <li><a href="#">Apple</a></li> <li><a href="#">Banana</a></li> <li><a href="#">Orange</a></li> <li class="divider"></li> <li><a href="#">Kale</a></li> <li><a href="#">Spinach</a></li> </ul> </li> </ul> </section> </nav> <div style="padding:20px;"> <h3>带有有分割线的下拉菜单</h3> <p> .divider 类用于设置下拉菜单的分割线。</p> </div> <!-- 初始化 Foundation JS --> <script> $(document).ready(function() { $(document).foundation(); }) </script> </body> </html>
Run the instance»
Click the "Run Instance" button to view the online instance
Drop-down menu label
Add the <label>
element inside <li>
to set the label (title) of the drop-down menu:
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> <nav class="top-bar" data-topbar> <ul class="title-area"> <li class="name"> <h1><a href="#">WebSiteName</a></h1> </li> <!-- 小屏幕上折叠按钮: 去掉 .menu-icon 类,可以去除图标。 如果需要只显示图片,可以删除 "Menu" 文本 --> <li class="toggle-topbar menu-icon"><a href="#"><span>Menu</span></a></li> </ul> <section class="top-bar-section"> <ul class="left"> <li class="active"><a href="#">Home</a></li> <li class="has-dropdown"> <a href="#">Dropdown</a> <ul class="dropdown"> <li><label>Fruit</label></li> <li><a href="#">Apple</a></li> <li><a href="#">Banana</a></li> <li><a href="#">Orange</a></li> <li class="divider"></li> <li><label>Vegetable</label></li> <li><a href="#">Kale</a></li> <li><a href="#">Spinach</a></li> </ul> </li> </ul> </section> </nav> <div style="padding:20px;"> <h3>下拉菜单标签(标题)</h3> <p>使用 label 元素为下拉菜单设置标签(标题)。</p> </div> <!-- 初始化 Foundation JS --> <script> $(document).ready(function() { $(document).foundation(); }) </script> </body> </html>
Run Instance»
Click the "Run Instance" button to view the online instance
Embedded drop-down menu
The drop-down menu can embed another drop-down menu:
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> <nav class="top-bar" data-topbar> <ul class="title-area"> <li class="name"> <h1><a href="#">WebSiteName</a></h1> </li> <!-- 小屏幕上折叠按钮: 去掉 .menu-icon 类,可以去除图标。 如果需要只显示图片,可以删除 "Menu" 文本 --> <li class="toggle-topbar menu-icon"><a href="#"><span>Menu</span></a></li> </ul> <section class="top-bar-section"> <ul class="left"> <li class="has-dropdown"> <a href="#">Dropdown</a> <ul class="dropdown"> <li><label>Level 1</label></li> <li><a href="#">Link</a></li> <li><a href="#">Link</a></li> <li class="has-dropdown"> <a href="#">New dropdown</a> <ul class="dropdown"> <li><label>Level 2</label></li> <li><a href="#">2nd level dropdown</a></li> <li><a href="#">2nd level dropdown</a></li> <li class="has-dropdown"> <a href="#">New dropdown</a> <ul class="dropdown"> <li><label>Level 3</label></li> <li><a href="#">3rd level dropdown</a></li> <li><a href="#">3rd level dropdown</a></li> </ul> </li> </ul> </li> </ul> </li> </ul> </section> </nav> <div style="padding:20px;"> <h3>导航栏内嵌下拉菜单</h3> <p>该实例演示了下拉菜单中再嵌入下拉菜单。</p> </div> <!-- 初始化 Foundation JS --> <script> $(document).ready(function() { $(document).foundation(); }) </script> </body> </html>
Run instance»
Click the "Run Instance" button to view the online instance
Clickable
By default, the drop-down menu of the navigation bar is displayed after the mouse moves over it. We can use data-options="is_hover: false"
Attribute to set the navigation bar to be displayed after the mouse is clicked:
Example
<!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> <nav class="top-bar" data-topbar data-options="is_hover: false"> <ul class="title-area"> <li class="name"> <h1><a href="#">WebSiteName</a></h1> </li> <!-- 小屏幕上折叠按钮: 去掉 .menu-icon 类,可以去除图标。 如果需要只显示图片,可以删除 "Menu" 文本 --> <li class="toggle-topbar menu-icon"><a href="#"><span>Menu</span></a></li> </ul> <section class="top-bar-section"> <ul class="left"> <li class="active"><a href="#">Home</a></li> <li class="has-dropdown"> <a href="#">Dropdown</a> <ul class="dropdown"> <li><a href="#">First link in dropdown</a></li> <li><a href="#">Second link in dropdown</a></li> <li class="active"><a href="#">Active link in dropdown</a></li> </ul> </li> </ul> </section> </nav> <div style="padding:20px;"> <h3>点击下拉菜单 With Clickable Dropdown</h3> <p>默认情况下导航栏的下拉菜单在鼠标移动过去后显示,我们可以使用 <code>data-options="is_hover: false"</code> 属性来设置导航栏在鼠标在点击后显示。</p> </div> <!-- 初始化 Foundation JS --> <script> $(document).ready(function() { $(document).foundation(); }) </script> </body> </html>
Run Instance»
Click the "Run Instance" button to view the online instance
Buttons and icons on the navigation bar
You can navigate Place icons and buttons on the bar:
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> <nav class="top-bar" data-topbar> <ul class="title-area"> <li class="name"> <h1><a href="#">WebSiteName</a></h1> </li> <!-- 小屏幕上折叠按钮: 去掉 .menu-icon 类,可以去除图标。 如果需要只显示图片,可以删除 "Menu" 文本 --> <li class="toggle-topbar menu-icon"><a href="#"><span>Menu</span></a></li> </ul> <section class="top-bar-section"> <ul class="left"> <li><a href="#">Page 1</a></li> <li><a href="#">Page 2</a></li> <li><a href="#" class="button">Button Link</a></li> </ul> </section> </nav> <div style="padding:20px;"> <h3>头部工具条按钮</h3> <p>头部工具条按钮实例。</p> </div> <!-- 初始化 Foundation JS --> <script> $(document).ready(function() { $(document).foundation(); }) </script> </body> </html>
Run Instance»
Click the "Run Instance" button to view online Example
You can put an icon on the navigation bar. For more picture styles, you can view the Foundation icon tutorial:
Example
<!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"> <!-- Foundation 图标样式 --> <link rel="stylesheet" href="http://static.php.cn/assets/foundation-icons/foundation-icons.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> <nav class="top-bar" data-topbar> <section class="top-bar-section"> <ul class="left"> <li class="active"><a href="#"><i class="fi-home"></i> Home</a></li> <li><a href="#"><i class="fi-torso"></i> Sign Up</a></li> <li><a href="#"><i class="fi-magnifying-glass"></i> Search</a></li> </ul> </section> </nav> <div style="padding:20px;"> <h3>工具条图标</h3> <p>工具条上显示图标实例。</p> </div> <!-- 初始化 Foundation JS --> <script> $(document).ready(function() { $(document).foundation(); }) </script> </body> </html>
Run Instance»
Click the "Run Instance" button to view the online instance
Fixed navigation bar
The navigation bar can be fixed in Top of page.
The navigation bar at the top will not move when the page is scrolled.
To fix the navigation bar, you only need to place the navigation bar inside <div class="fixed">
:
Example
<!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="height:1500px"> <div class="fixed"> <nav class="top-bar" data-topbar> <ul class="title-area"> <li class="name"> <h1><a href="#">WebSiteName</a></h1> </li> <!-- 小屏幕上折叠按钮: 去掉 .menu-icon 类,可以去除图标。 如果需要只显示图片,可以删除 "Menu" 文本 --> <li class="toggle-topbar menu-icon"><a href="#"><span>Menu</span></a></li> </ul> <section class="top-bar-section"> <ul class="left"> <li class="active"><a href="#">Home</a></li> <li><a href="#">Page 1</a></li> <li><a href="#">Page 2</a></li> <li><a href="#">Page 3</a></li> &am