UIkit3.x文档

按钮

轻松创建外观精美的按钮,它们具有不同的样式。

用法

要使用此组件,请将 .uk-button class 和 .uk-button-default 等修饰符添加到 <a><button> 元素。将 disabled 属性添加到 <button> 元素可以禁用按钮。

<a class="uk-button uk-button-default" href=""></a>

<button class="uk-button uk-button-default"></button>

<button class="uk-button uk-button-default" disabled></button>
  • Link

  • <p uk-margin>
        <a class="uk-button uk-button-default" href="#">Link</a>
        <button class="uk-button uk-button-default">Button</button>
        <button class="uk-button uk-button-default" disabled>Disabled</button>
    </p>

Note 如果在一行中显示多个按钮,当它们堆叠在较小的视口上时,可以为它们添加上边距。只需将Margin 组件中的uk-margin 属性添加到其父元素。


样式修饰

有几种样式修饰符可用。只需添加以下类之一即可应用不同的外观。

Class Description
.uk-button-default 默认按钮样式。
.uk-button-primary 表示主要动作。
.uk-button-secondary 表示重要的动作。
.uk-button-danger 表示危险或负面行为。
.uk-button-text 应用替代的印刷样式。
.uk-button-link 制造一个 <button> 使它看起来和 <a> 元素一样。
<button class="uk-button uk-button-primary"></button>
  • <p uk-margin>
        <button class="uk-button uk-button-default">Default</button>
        <button class="uk-button uk-button-primary">Primary</button>
        <button class="uk-button uk-button-secondary">Secondary</button>
        <button class="uk-button uk-button-danger">Danger</button>
        <button class="uk-button uk-button-text">Text</button>
        <button class="uk-button uk-button-link">Link</button>
    </p>

尺寸修改器

.uk-button-small.uk-button-large class 添加到按钮以使其变小或变大。

<button class="uk-button uk-button-default uk-button-small"></button>

<button class="uk-button uk-button-default uk-button-large"></button>
  • <p uk-margin>
        <button class="uk-button uk-button-default uk-button-small">Small button</button>
        <button class="uk-button uk-button-primary uk-button-small">Small button</button>
        <button class="uk-button uk-button-secondary uk-button-small">Small button</button>
    </p>
    
    <p uk-margin>
        <button class="uk-button uk-button-default uk-button-large">Large button</button>
        <button class="uk-button uk-button-primary uk-button-large">Large button</button>
        <button class="uk-button uk-button-secondary uk-button-large">Large button</button>
    </p>

宽度修改器

Width 组件中添加 .uk-width-1-1 class 按钮可以使该按钮占据整个宽度。

Example

  • <button class="uk-button uk-button-default uk-width-1-1 uk-margin-small-bottom">Button</button>
    <button class="uk-button uk-button-primary uk-width-1-1 uk-margin-small-bottom">Button</button>
    <button class="uk-button uk-button-secondary uk-width-1-1">Button</button>

按钮组

要创建按钮组,请将 .uk-button-group class 添加到按钮外层的 <div> 元素中就可以了。不需要更多的标记。

<div class="uk-button-group">
    <button class="uk-button uk-button-default"></button>
    <button class="uk-button uk-button-default"></button>
    <button class="uk-button uk-button-default"></button>
</div>
  • <div>
        <div class="uk-button-group">
            <button class="uk-button uk-button-secondary">Button</button>
            <button class="uk-button uk-button-secondary">Button</button>
            <button class="uk-button uk-button-secondary">Button</button>
        </div>
    </div>
    
    <div class="uk-margin-small">
        <div class="uk-button-group">
            <button class="uk-button uk-button-primary">Button</button>
            <button class="uk-button uk-button-primary">Button</button>
            <button class="uk-button uk-button-primary">Button</button>
        </div>
    </div>
    
    <div>
        <div class="uk-button-group">
            <button class="uk-button uk-button-danger">Button</button>
            <button class="uk-button uk-button-danger">Button</button>
            <button class="uk-button uk-button-danger">Button</button>
        </div>
    </div>

带下拉菜单的按钮

可以使用按钮来触发 Dropdown菜单组件的下拉菜单。

<!-- A button toggling a dropdown -->
<button class="uk-button uk-button-default" type="button"></button>
<div uk-dropdown></div>
  • <div class="uk-inline">
        <button class="uk-button uk-button-default" type="button">Dropdown</button>
        <div uk-dropdown>
            <ul class="uk-nav uk-dropdown-nav">
                <li class="uk-active"><a href="#">Active</a></li>
                <li><a href="#">Item</a></li>
                <li class="uk-nav-header">Header</li>
                <li><a href="#">Item</a></li>
                <li><a href="#">Item</a></li>
                <li class="uk-nav-divider"></li>
                <li><a href="#">Item</a></li>
            </ul>
        </div>
    </div>

带有下拉菜单的按钮组

使用按钮组将按钮拆分为左侧的标准操作和右侧的下拉开关。只需将切换按钮和下拉列表包装在 <div> 元素内,然后从Utility 组件中添加 .uk-inline class 就可以了

<!-- A button group with a dropdown -->
<div class="uk-button-group">
    <button class="uk-button uk-button-default"></button>
    <div class="uk-inline">

        <!-- The button toggling the dropdown -->
        <button class="uk-button uk-button-default" type="button"></button>
        <div uk-dropdown="mode: click; boundary: ! .uk-button-group; boundary-align: true;"></div>

    </div>
</div>
  • 
    <div class="uk-button-group">
        <button class="uk-button uk-button-default">Dropdown</button>
        <div class="uk-inline">
            <button class="uk-button uk-button-default" type="button"><span uk-icon="icon:  triangle-down"></span></button>
            <div uk-dropdown="mode: click; boundary: ! .uk-button-group; boundary-align: true;">
                <ul class="uk-nav uk-dropdown-nav">
                    <li class="uk-active"><a href="#">Active</a></li>
                    <li><a href="#">Item</a></li>
                    <li class="uk-nav-header">Header</li>
                    <li><a href="#">Item</a></li>
                    <li><a href="#">Item</a></li>
                    <li class="uk-nav-divider"></li>
                    <li><a href="#">Item</a></li>
                </ul>
            </div>
        </div>
    </div>