Foundation button group


Button Group

Foundation can create a series of buttons in the same row.

You can create a button group using the <ul> element and adding the .button-group class:

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>

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

Run Instance»

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


Vertical Button Group

Vertical button groups are created using the .stack class. Note that the button spans the entire width of the parent element:

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>

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

Run Instance»

Click "Run Instance" "Button view online example

.stack-for-small class is used for small-sized screens. The buttons are arranged from horizontal to vertical:

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>

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

Run instance»

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


##circle Corner Button Group

Use the

.radius and .round classes in the button group to add rounded corners to the buttons:

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>

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

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


Evenly Extend Button Group

.even-num Class is used to evenly distribute the width of the buttons in the button group and span 100% of the width of the parent element.

num is the number of buttons in the button group, from 1 to 8:

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

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

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


The drop-down menu button

The drop-down menu button allows users to select settings Good value:

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>

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

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

Example analysis

.dropdown class creates a drop-down menu button.

Open a dropdown menu using a button or link with the data-dropdown="id" attribute.

id The value needs to match the content of the dropdown (id01).

Add the .f-dropdown class and the data-dropdown-content attribute in <ul> to create the content of the drop-down menu.

Finally initialize Foundation JS.


Split button

We can also create a drop-down menu of split buttons. Just add the .split class to the button and use the span element to generate a directional arrow button:

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>

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

Run Instance»

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

注意## Tip:We will learn more about drop-down menus in later tutorials.