Materialize CSS提供了下拉功能。它提供了几个CSS类来使ul元素成为下拉列表, 并将ul元素的id添加到button或anchor元素的data-activates属性中。
以下是类及其效果的列表:
Index | Class name | Description |
---|---|---|
1) | dropdown-content | 它用于将ul标识为实现下拉组件。 ul元素必需。 |
2) | data-activates | 用于指定下拉ul元素的ID。 |
如何使用下拉菜单?
要将下拉列表添加到任何按钮, 必须确保data-activates属性与<ul>标记中的id匹配。你可以使用<li class =” divider”> </ li>标记添加分隔线。你还可以添加图标。只需将图标添加到锚标记中即可。
例子
让我们以一个示例来演示下拉列表:
<!DOCTYPE html>
<html>
<head>
<title>The Materialize Dropdowns Example</title>
<meta name = "viewport" content = "width = device-width, initial-scale = 1">
<link rel = "stylesheet"
href = "https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel = "stylesheet"
href = "https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.3/css/materialize.min.css">
<script type = "text/javascript"
src = "https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.3/js/materialize.min.js">
</script>
</head>
<body class = "container">
<h3>Drop Down Example</h3>
<ul id = "dropdown" class = "dropdown-content">
<li><a href = "#">Inbox<span class = "badge">12</span></a></li>
<li><a href = "#!">Unread<span class = "new badge">4</span></a></li>
<li><a href = "#">Sent</a></li>
<li class = "divider"></li>
<li><a href = "#">Outbox<span class = "badge">14</span></a></li>
</ul>
<a class = "btn dropdown-button" href = "#" data-activates = "dropdown">Mail Box
<i class = "mdi-navigation-arrow-drop-down right"></i></a>
</body>
</html>
立即测试
输出
评论前必须登录!
注册