轻松创建美观的按钮,有不同的样式可供选择。
要应用此组件,请将 .uk-button
类和一个修饰符(例如 .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>
<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>
注意 如果你在一行中显示多个按钮,当它们在较小的视口上堆叠时,你可以向它们添加顶部边距。 只需将 边距组件的 uk-margin
属性添加到它们的父元素。
有几个样式修饰符可用。只需添加以下类之一即可应用不同的外观。
类 | 描述 |
---|---|
.uk-button-default |
默认按钮样式。 |
.uk-button-primary |
指示主要操作。 |
.uk-button-secondary |
指示重要操作。 |
.uk-button-danger |
指示危险或负面操作。 |
.uk-button-text |
应用排版样式。 |
.uk-button-link |
应用纯链接样式。 |
<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
类添加到按钮,使其更小或更大。
<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>
添加 宽度组件 的 .uk-width-1-1
类,按钮将占据整个宽度。
<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>
要创建一个按钮组,请在按钮周围的 <div>
元素添加 .uk-button-group
类。 就是这样! 无需进一步标记。
<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>
可以使用按钮从 下拉组件触发下拉菜单。
<!-- 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>
元素中,并从 实用工具组件添加 .uk-inline
类。
<!-- 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; target: !.uk-button-group;"></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" aria-label="Toggle Dropdown"><span uk-icon="icon: triangle-down"></span></button>
<div uk-dropdown="mode: click; target: !.uk-button-group;">
<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>