天天看點

Foundation 按鈕組

Foundation 可以在同一行内建立一系列的按鈕。

可以使用 <code>&lt;ul&gt;</code> 元素并添加 <code>.button-group</code> 類來建立按鈕組:

&lt;ul class="button-group"&gt;

  &lt;li&gt;&lt;button type="button"

class="button"&gt;Apple&lt;/button&gt;&lt;/li&gt;

class="button"&gt;Samsung&lt;/button&gt;&lt;/li&gt;

class="button"&gt;Sony&lt;/button&gt;&lt;/li&gt;

&lt;/ul&gt;

垂直按鈕組使用 <code>.stack</code> 類來建立。注意,按鈕會跨越父元素的整個寬度:

&lt;ul class="button-group stack"&gt;

<code>.stack-for-small</code> 類用于小尺寸的螢幕,按鈕有水準排列變為垂直排列:

&lt;ul class="button-group stack-for-small"&gt;

按鈕組中使用 <code>.radius</code> 和 <code>.round</code> 類為按鈕添加圓角效果:

&lt;ul class="button-group radius"&gt;

&lt;li&gt;&lt;button type="button" class="button"&gt;Apple&lt;/button&gt;&lt;/li&gt;

&lt;li&gt;&lt;button type="button" class="button"&gt;Samsung&lt;/button&gt;&lt;/li&gt;

&lt;li&gt;&lt;button type="button" class="button"&gt;Sony&lt;/button&gt;&lt;/li&gt;

&lt;ul class="button-group round"&gt;

  &lt;li&gt;&lt;button

type="button" class="button"&gt;Apple&lt;/button&gt;&lt;/li&gt;

type="button" class="button"&gt;Samsung&lt;/button&gt;&lt;/li&gt;

type="button" class="button"&gt;Sony&lt;/button&gt;&lt;/li&gt;

<code>.even-num</code> 類用于在按鈕組中均勻的配置設定按鈕的寬度并跨越父元素 100% 寬度。

num 為按鈕組中按鈕的數量,從 1 到 8:

&lt;ul class="button-group even-3"&gt;

&lt;ul class="button-group

even-5"&gt;

class="button"&gt;HTC&lt;/button&gt;&lt;/li&gt;

class="button"&gt;Huawei&lt;/button&gt;&lt;/li&gt;

even-8"&gt;

  &lt;li&gt;&lt;button type="button" class="button"&gt;A&lt;/button&gt;&lt;/li&gt;

&lt;li&gt;&lt;button type="button" class="button"&gt;B&lt;/button&gt;&lt;/li&gt;

&lt;li&gt;&lt;button type="button" class="button"&gt;C&lt;/button&gt;&lt;/li&gt;

&lt;li&gt;&lt;button type="button" class="button"&gt;D&lt;/button&gt;&lt;/li&gt;

&lt;li&gt;&lt;button type="button" class="button"&gt;E&lt;/button&gt;&lt;/li&gt;

&lt;li&gt;&lt;button type="button" class="button"&gt;F&lt;/button&gt;&lt;/li&gt;

&lt;li&gt;&lt;button type="button" class="button"&gt;G&lt;/button&gt;&lt;/li&gt;

&lt;li&gt;&lt;button type="button" class="button"&gt;H&lt;/button&gt;&lt;/li&gt;

下拉菜單按鈕可以讓使用者選取設定好的值:

&lt;!-- Trigger the dropdown --&gt;

&lt;a href="#" data-dropdown="id01" class="button dropdown"&gt;Dropdown Button&lt;/a&gt;

&lt;!-- The actual dropdown --&gt;

&lt;ul id="id01" data-dropdown-content class="f-dropdown"&gt;

  &lt;li&gt;&lt;a

href="#"&gt;Link 1&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;&lt;a href="#"&gt;Link 2&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href="#"&gt;Link 3&lt;/a&gt;&lt;/li&gt;

&lt;!-- Initialize Foundation JS --&gt;

&lt;script&gt;

$(document).ready(function() {

$(document).foundation();

})

&lt;/script&gt;

<code>.dropdown</code> 類建立一個下拉菜單按鈕。

使用帶有 <code>data-dropdown="id"</code> 屬性的按鈕或連結打開下拉菜單。

id 值需要與下拉菜單的内容 (id01) 比對。

在 <code>&lt;ul&gt;</code> 中添加 <code>.f-dropdown</code> 類和 <code>data-dropdown-content</code> 屬性來建立下拉菜單的内容。

最後初始化 Foundation JS。

我們也可以建立一個分割按鈕的下拉菜單。隻需要在按鈕中添加 <code>.split</code> 類并使用 span 元素生成一個方向箭的按鈕:

&lt;button class="button split"&gt;Split Button

  &lt;span

data-dropdown="id01"&gt;&lt;/span&gt;

&lt;/button&gt;

&lt;ul id="id01" data-dropdown-content

class="f-dropdown"&gt;

  &lt;li&gt;&lt;a href="#"&gt;Link 1&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href="#"&gt;Link 2&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;&lt;a href="#"&gt;Link 3&lt;/a&gt;&lt;/li&gt;