Foundation 按鈕群組
按鈕組
Foundation 可以在同一行內建立一系列的按鈕。
可以使用<ul>
元素並且新增.button-group
類別來建立按鈕群組:
實例
<!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> <div style="padding:20px;"> <h2>按钮组</h2> <ul class="button-group"> <li><button type="button" class="button">Apple</button></li> <li><button type="button" class="button">Samsung</button></li> <li><button type="button" class="button">Sony</button></li> </ul> </div> </body> </html>
執行實例»
#點擊"執行實例"按鈕查看線上實例
垂直按鈕群組
垂直按鈕組使用.stack
類別來建立。注意,按鈕會跨越父元素的整個寬度:
實例
<!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> <div style="padding:20px;"> <h2>垂直按钮组</h2> <p>垂直按钮组使用 .stack 类来创建。注意,按钮会跨越父元素的整个宽度。</p> <ul class="button-group stack"> <li><button type="button" class="button">Apple</button></li> <li><button type="button" class="button">Samsung</button></li> <li><button type="button" class="button">Sony</button></li> </ul> </div> </body> </html>
##運行實例»點擊"運行實例" 按鈕查看線上實例
.stack-for-small 類別用於小尺寸的螢幕,按鈕有水平排列變為垂直排列:
實例
運行實例»點擊"運行實例"按鈕查看在線實例
##圓角按鈕組<!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> <div style="padding:20px;"> <h2>垂直按钮组</h2> <p>.stack-for-small 类用于小尺寸的屏幕,按钮有水平排列变为垂直排列(重置窗口大小查看效果):</p> <ul class="button-group stack-for-small"> <li><button type="button" class="button">Apple</button></li> <li><button type="button" class="button">Samsung</button></li> <li><button type="button" class="button">Sony</button></li> </ul> </div> </body> </html>
運行實例»點擊"運行實例"按鈕查看在線實例
按鈕組中使用
.radius 和.round
類別為按鈕新增圓角效果:
<!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>
<div style="padding:20px;">
<h2>圆角按钮组</h2>
<p>圆角按钮组:</p>
<ul class="button-group radius">
<li><button type="button" class="button">Apple</button></li>
<li><button type="button" class="button">Samsung</button></li>
<li><button type="button" class="button">Sony</button></li>
</ul>
<p>圆形按钮组:</p>
<ul class="button-group round">
<li><button type="button" class="button">Apple</button></li>
<li><button type="button" class="button">Samsung</button></li>
<li><button type="button" class="button">Sony</button></li>
</ul>
</div>
</body>
</html>
執行實例»點擊"運行實例" 按鈕查看線上實例
.even-num
類別用於在按鈕群組中均勻的分配按鈕的寬度並跨越父元素100% 寬度。
為按鈕群組中按鈕的數量,從1 到8:
實例<!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">
<h3>均匀延展按钮组:</h3>
<p>均匀延展三个按钮:</p>
<ul class="button-group even-3">
<li><button type="button" class="button">Apple</button></li>
<li><button type="button" class="button">Samsung</button></li>
<li><button type="button" class="button">Sony</button></li>
</ul>
<p>均匀延展五个按钮:</p>
<ul class="button-group even-5">
<li><button type="button" class="button">Apple</button></li>
<li><button type="button" class="button">Samsung</button></li>
<li><button type="button" class="button">Sony</button></li>
<li><button type="button" class="button">HTC</button></li>
<li><button type="button" class="button">Huawei</button></li>
</ul>
<p>均匀延展八个按钮:</p>
<ul class="button-group even-8">
<li><button type="button" class="button">A</button></li>
<li><button type="button" class="button">B</button></li>
<li><button type="button" class="button">C</button></li>
<li><button type="button" class="button">D</button></li>
<li><button type="button" class="button">E</button></li>
<li><button type="button" class="button">F</button></li>
<li><button type="button" class="button">G</button></li>
<li><button type="button" class="button">H</button></li>
</ul>
</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> <div style="padding:20px;"> <h2>下拉菜单按钮</h2> <a href="#" data-dropdown="id01" class="button dropdown">Dropdown Button</a> <ul id="id01" data-dropdown-content class="f-dropdown"> <li><a href="#">Link 1</a></li> <li><a href="#">Link 2</a></li> <li><a href="#">Link 3</a></li> </ul> </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> <div style="padding:20px;"> <h2>下拉菜单按钮</h2> <a href="#" data-dropdown="id01" class="button dropdown">Dropdown Button</a> <ul id="id01" data-dropdown-content class="f-dropdown"> <li><a href="#">Link 1</a></li> <li><a href="#">Link 2</a></li> <li><a href="#">Link 3</a></li> </ul> </div> <!-- 初始化 Foundation JS --> <script> $(document).ready(function() { $(document).foundation(); }) </script> </body> </html>
#執行實例»
點擊"運行實例" 按鈕查看線上實例
實例解析
.dropdown
類別建立一個下拉式選單按鈕。
使用帶有 data-dropdown="id"
屬性的按鈕或連結開啟下拉式功能表。
id 值需要與下拉式選單的內容 (id01) 相符。
在 <ul>
中新增 .f-dropdown
類別和 data-dropdown-content
屬性來建立下拉式選單的內容。
最後初始化 Foundation JS。
分割按鈕
我們也可以建立一個分割按鈕的下拉式選單。只需要在按鈕中加入.split
類別並使用span 元素產生一個方向箭的按鈕:
##實例##
運行實例»
點擊"運行實例" 按鈕查看線上實例
##<!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>
<div style="padding:20px;">
<h2>分割按钮</h2>
<button class="button split">Split Button <span data-dropdown="id01"></span></button>
<ul id="id01" data-dropdown-content class="f-dropdown">
<li><a href="#">Link 1</a></li>
<li><a href="#">Link 2</a></li>
<li><a href="#">Link 3</a></li>
</ul>
</div>
<!-- Initialize Foundation JS -->
<script>
$(document).ready(function() {
$(document).foundation();
})
</script>
</body>
</html>
運行實例»點擊"運行實例" 按鈕查看線上實例
#提示: | 後面的教學我們將學到更多關於下拉式選單是知識。 |
---|