Foundation 頂部導覽列
頂部導覽列放在頁面頭部:
實例
<!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>
運行實例»##點擊"運行實例" 按鈕檢視線上實例
<nav class="top-bar" data-topbar> 建立標準工具列。
.title-area 類別定義了網站logo區域 (必須防止
li.name 內) 。螢幕變小後你就可以看到一個 "menu" 按鈕。 Foundation 的選單會根據螢幕尺寸自動折疊喝延展:
li.toggle-topbar menu.icon 類別建立了一個選單的按鈕,點擊它可以顯示被隱藏的選項。
提示: 重置瀏覽器視窗查看效果。
.top-bar-section 定義了導覽的連結部分。
.left 類別指定連結左對齊。
.active 類別用於顯示選取的項,背景為藍色。
提示: 如果你想要導航連結右邊對齊可以將.left 修改為
.right :
<!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>
運行實例»點擊"運行實例"按鈕查看線上實例##你可以同時設定左邊對齊與右邊對齊:
<!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>
#運行實例»點擊"運行實例" 按鈕查看線上實例導覽列可以透過
類別來新增分割線(大螢幕上是垂直的線,小螢幕上是水平線):
<!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>
運行實例»點擊"運行實例"按鈕查看線上實例
頂部導覽列可以設定下拉式選單。
可以透過在
<li> 元素上新增.has-dropdown
類別來設定下拉式選單:##實例
<!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>
點擊"運行實例"按鈕查看線上實例
分割線
.divider
類別來設定下拉式選單的分割線:實例
<!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>##執行實例»點擊"運行實例" 按鈕查看線上實例
下拉選單標籤
在<li>
內加入<label>
元素來設定下拉式選單的標籤(標題):
實例
<!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>
運行實例»
點擊"運行實例" 按鈕查看線上實例
內嵌下拉選單
下拉選單可以再嵌入一個下拉選單:
實例
<!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>
執行實例»
點擊"運行實例" 按鈕查看線上實例
可點擊
預設情況下導航列的下拉式選單在滑鼠移動過去後顯示,我們可以使用data-options="is_hover: false"
屬性來設定導覽列在滑鼠在點擊後顯示:
實例
<!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>
#執行實例»
點擊"運行實例" 按鈕查看線上實例
#導航列上的按鈕及圖示
你可以在導航欄上放置圖示和按鈕:
實例
<!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>
#執行實例»
點擊"運行實例"按鈕查看在線實例
你可以在導覽列上放上圖標,更多圖片樣式可以查看Foundation 圖標教學:
實例
<!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>
執行實例»
點擊"執行實例" 按鈕查看線上實例
#固定導覽列
導覽列可以固定在頁面頂部。
頁面捲動時導覽列在頂部是不會動的。
要固定導覽列只需將導覽列放在<div class="fixed">
內即可:
實例
<!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