Foundation drop-down menu


Foundation drop-down menu allows the user to select a value from a predefined drop-down list:

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>

Run Instance»

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

Instance analysis

.dropdown class adds a downward arrow symbol" icon to the button .

Use the data-dropdown="id" attribute of the button or link to open the dropdown menu. The value needs to match the content of the dropdown menu (id01). Add

.f-dropdown## in <div>, <nav>,

<ul>. # Class and data-dropdown-content

attributes to create the content of the dropdown menu

Finally initialize Foundation JS ##Note: On small screens. Above, the width of all drop-down menus is 100%.

Drop-down menu sizes

use

.tiny, .small

, #. ##.medium
,

.large

or

.mega to modify the width of the drop-down menu Note: on small screens. , the width of all drop-down menus is 100% 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="padding:20px">

<!-- Tiny Dropdown: max-width is 200px -->
<a href="#" data-dropdown="id01" class="button dropdown">Tiny</a>
<ul id="id01" data-dropdown-content class="f-dropdown tiny">
  <li><a href="#">Link 1</a></li>
  <li><a href="#">Link 2</a></li>
  <li><a href="#">Link 3</a></li>
</ul>
<br>

<!-- Small Dropdown: max-width is 300px  -->
<a href="#" data-dropdown="id02" class="button dropdown">Small</a>
<ul id="id02" data-dropdown-content class="f-dropdown small">
  <li><a href="#">Link 1</a></li>
  <li><a href="#">Link 2</a></li>
  <li><a href="#">Link 3</a></li>
</ul>
<br>

<!-- Medium Dropdown: max-width is 500px  -->
<a href="#" data-dropdown="id03" class="button dropdown">Medium</a>
<ul id="id03" data-dropdown-content class="f-dropdown medium">
  <li><a href="#">Link 1</a></li>
  <li><a href="#">Link 2</a></li>
  <li><a href="#">Link 3</a></li>
</ul>
<br>

<!-- Large Dropdown: max-width is 800px  -->
<a href="#" data-dropdown="id04" class="button dropdown">Large</a>
<ul id="id04" data-dropdown-content class="f-dropdown large">
  <li><a href="#">Link 1</a></li>
  <li><a href="#">Link 2</a></li>
  <li><a href="#">Link 3</a></li>
</ul>
<br>

<!-- Mega Dropdown: 100% width -->
<a href="#" data-dropdown="id05" class="button dropdown">Mega</a>
<ul id="id05" data-dropdown-content class="f-dropdown mega">
  <li><a href="#">Link 1</a></li>
  <li><a href="#">Link 2</a></li>
  <li><a href="#">Link 3</a></li>
</ul>

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

</body>
</html>

Run Example»

Click "Run Example." "Button to view online examples

Drop-down menu margin

You can use the .content class to add padding to 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 style="padding:20px">

<h2>下拉菜单内容项</h2>
<a href="#" data-dropdown="id01" class="button dropdown">没有内边距</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>

<a href="#" data-dropdown="id02" class="button dropdown">有内边距</a>
<ul id="id02" data-dropdown-content class="f-dropdown content">
  <li><a href="#">Link 1</a></li>
  <li><a href="#">Link 2</a></li>
  <li><a href="#">Link 3</a></li>
</ul>

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

</body>
</html>

Run Instance»

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

Other instances

<div> Add multimedia elements to 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 style="padding:20px;">

<h2>下拉菜单内容</h2>
<a href="#" data-dropdown="id01" class="button dropdown">下拉按钮</a>
<div id="id01" data-dropdown-content class="f-dropdown medium content">
  <h4>Paris Title</h4>
  <p>Some text.. some text..</p>
  <img src="paris.jpg" alt="Paris" width="400" height="300">
  <p>Paris, je t'aime.</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

Drop-down menu direction

The drop-down menu is at the bottom by default, you can add it by adding data-options="align:left|right|top" to change its direction:

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;"><br><br><!-- Add <br> elements to enable top dropdown -->

<h2>下拉菜单方向</h2>
<a href="#" data-dropdown="id01" data-options="align:right" class="button dropdown">右边</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>

<a href="#" data-dropdown="id02" data-options="align:top" class="button dropdown">顶部</a>
<ul id="id02" 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>

<a href="#" data-dropdown="id03" data-options="align:bottom" class="button dropdown">底部</a>
<ul id="id03" 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>

<a href="#" data-dropdown="id04" data-options="align:left" class="button dropdown">左边</a>
<ul id="id04" 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>

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

</body>
</html>

Run instance»

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

Drop-down menu trigger condition

By default, the drop-down menu is displayed after clicking the button. If you need to display it after the mouse moves up, you can use data-options="is_hover:true" attribute on the button:

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>
<a href="#" data-dropdown="id01" data-options="is_hover:true" class="button dropdown">鼠标移动到我这</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>

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

</body>
</html>


Run instance»

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


Split button

We can add on the button .split class to set a button with a split effect. After splitting, it will Generate a downward icon button on the <span> 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>

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

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