轻松创建美观的搜索框。
搜索组件由搜索表单和搜索输入框构成。
Class/Attribute | Description |
---|---|
.uk-search |
添加到容器元素以定义搜索组件。 |
.uk-search-input |
添加到 <input> 元素中以创建搜索框。 |
<form class="uk-search">
<input class="uk-search-input" type="search" placeholder="">
</form>
默认情况下,搜索没有额外样式。下方示例中,我们使用.uk-search-default
类修饰。
<form class="uk-search uk-search-default">
<input class="uk-search-input" type="search" placeholder="Search...">
</form>
要创建搜索图标,请将uk-search-icon
属性添加到<span>
元素。若要更改对齐方式,请添加 .uk-search-icon-flip
class。
<form class="uk-search uk-search-default">
<span uk-search-icon></span>
<input class="uk-search-input" type="search" placeholder="">
</form>
<div class="uk-margin">
<form class="uk-search uk-search-default">
<span uk-search-icon></span>
<input class="uk-search-input" type="search" placeholder="Search...">
</form>
</div>
<div class="uk-margin">
<form class="uk-search uk-search-default">
<span class="uk-search-icon-flip" uk-search-icon></span>
<input class="uk-search-input" type="search" placeholder="Search...">
</form>
</div>
使用<a>
或 <button>
元素创建可以点击的搜索图标。
<form class="uk-search uk-search-default">
<a href="" uk-search-icon></a>
<input class="uk-search-input" type="search" placeholder="">
</form>
<div class="uk-margin">
<form class="uk-search uk-search-default">
<a href="" uk-search-icon></a>
<input class="uk-search-input" type="search" placeholder="Search...">
</form>
</div>
<div class="uk-margin">
<form class="uk-search uk-search-default">
<a href="" class="uk-search-icon-flip" uk-search-icon></a>
<input class="uk-search-input" type="search" placeholder="Search...">
</form>
</div>
要应用默认搜索样式,请添加.uk-search-default
class。
<form class="uk-search uk-search-default">...</form>
<form class="uk-search uk-search-default">
<span uk-search-icon></span>
<input class="uk-search-input" type="search" placeholder="Search...">
</form>
如果要增加搜索的尺寸(比如在遮罩层上使用搜索组件),请添加.uk-search-large
class。
<form class="uk-search uk-search-large">...</form>
<form class="uk-search uk-search-large">
<span uk-search-icon></span>
<input class="uk-search-input" type="search" placeholder="Search...">
</form>
搜索组件可以用在Navbar 组件的导航栏上。只需添加 .uk-search-navbar
class。
<form class="uk-search uk-search-navbar">...</form>
<nav class="uk-navbar-container" uk-navbar>
<div class="uk-navbar-left">
<div class="uk-navbar-item">
<form class="uk-search uk-search-navbar">
<span uk-search-icon></span>
<input class="uk-search-input" type="search" placeholder="Search...">
</form>
</div>
</div>
</nav>
如果要在使用<a>
或 <button>
元素作为搜索图标时加入鼠标悬停状态效果,请添加.uk-search-toggle
class。要创建搜索图标本身,请添加 uk-search-icon
属性。
<a class="uk-search-toggle" href="" uk-search-icon></a>
搜索图标可用作切换开关,在导航栏内部以遮罩层、下拉或下拉菜单、外部模态框等形式打开搜索框。只需将.uk-navbar-toggle
class 添加到图标即可。
<div class="uk-navbar-container" uk-navbar>
<div class="uk-navbar-left">
<a class="uk-navbar-toggle" uk-search-icon uk-toggle href=""></a>
</div>
</div>
<nav class="uk-navbar-container uk-margin" uk-navbar>
<div class="nav-overlay uk-navbar-left">
<a class="uk-navbar-item uk-logo" href="#">Logo</a>
<ul class="uk-navbar-nav">
<li class="uk-active"><a href="#">Active</a></li>
<li><a href="#">Item</a></li>
</ul>
</div>
<div class="nav-overlay uk-navbar-right">
<a class="uk-navbar-toggle" uk-search-icon uk-toggle="target: .nav-overlay; animation: uk-animation-fade" href="#"></a>
</div>
<div class="nav-overlay uk-navbar-left uk-flex-1" hidden>
<div class="uk-navbar-item uk-width-expand">
<form class="uk-search uk-search-navbar uk-width-1-1">
<input class="uk-search-input" type="search" placeholder="Search..." autofocus>
</form>
</div>
<a class="uk-navbar-toggle" uk-close uk-toggle="target: .nav-overlay; animation: uk-animation-fade" href="#"></a>
</div>
</nav>
<nav class="uk-navbar-container uk-margin" uk-navbar>
<div class="uk-navbar-left">
<a class="uk-navbar-item uk-logo" href="#">Logo</a>
<ul class="uk-navbar-nav">
<li class="uk-active"><a href="#">Active</a></li>
<li><a href="#">Item</a></li>
</ul>
</div>
<div class="uk-navbar-right">
<div>
<a class="uk-navbar-toggle" uk-search-icon href="#"></a>
<div class="uk-drop" uk-drop="mode: click; pos: left-center; offset: 0">
<form class="uk-search uk-search-navbar uk-width-1-1">
<input class="uk-search-input" type="search" placeholder="Search..." autofocus>
</form>
</div>
</div>
</div>
</nav>
<nav class="uk-navbar-container uk-margin" uk-navbar>
<div class="uk-navbar-left">
<a class="uk-navbar-item uk-logo" href="#">Logo</a>
<ul class="uk-navbar-nav">
<li class="uk-active"><a href="#">Active</a></li>
<li><a href="#">Item</a></li>
</ul>
</div>
<div class="uk-navbar-right">
<div>
<a class="uk-navbar-toggle" href="#" uk-search-icon></a>
<div class="uk-navbar-dropdown" uk-drop="mode: click; cls-drop: uk-navbar-dropdown; boundary: !nav">
<div class="uk-grid-small uk-flex-middle" uk-grid>
<div class="uk-width-expand">
<form class="uk-search uk-search-navbar uk-width-1-1">
<input class="uk-search-input" type="search" placeholder="Search..." autofocus>
</form>
</div>
<div class="uk-width-auto">
<a class="uk-navbar-dropdown-close" href="#" uk-close></a>
</div>
</div>
</div>
</div>
</div>
</nav>
<nav class="uk-navbar uk-navbar-container uk-margin">
<div class="uk-navbar-left">
<a class="uk-navbar-item uk-logo" href="#">Logo</a>
<ul class="uk-navbar-nav">
<li class="uk-active"><a href="#">Active</a></li>
<li><a href="#">Item</a></li>
</ul>
</div>
<div class="uk-navbar-right">
<a class="uk-navbar-toggle" href="#modal-full" uk-search-icon uk-toggle></a>
</div>
</nav>
<div id="modal-full" class="uk-modal-full uk-modal" uk-modal>
<div class="uk-modal-dialog uk-flex uk-flex-center uk-flex-middle" uk-height-viewport>
<button class="uk-modal-close-full" type="button" uk-close></button>
<form class="uk-search uk-search-large">
<input class="uk-search-input uk-text-center" type="search" placeholder="Search..." autofocus>
</form>
</div>
</div>