搜索栏在桌面上可见,在移动设备上可扩展
Search Bar Visible In Desktop And Expandable In Mobile Devices
这是我的代码。
<style>
#searchformfix {
width: 50%;
border-right: 1px solid #E5E5E5;
border-left: 1px solid #E5E5E5;
position: relative;
background: #fff;
height: 40px;
display: inline-block;
border: 1px solid #219AEB;
border-radius: 5px;
margin-top: 5px;
}
#searchform {
margin: 0px 0 0;
padding: 0;
}
#searchform input[type="text"] {
background: #fff;
border: none;
float: left;
height: 100%;
transition: all 600ms cubic-bezier(0.215,0.61,0.355,1) 0s;
-moz-transition: all 300ms cubic-bezier(0.215,0.61,0.355,1) 0s;
-webkit-transition: all 600ms cubic-bezier(0.215,0.61,0.355,1) 0s;
-o-transition: all 600ms cubic-bezier(0.215,0.61,0.355,1) 0s;
color: #929292;
margin-left: 10px;
margin-top: 10px;
width: 80%;
}
button.fa.fa-search {
background: #FFF;
margin-top: 5px;
font-size: 24px;
float: right;
cursor: pointer;
}
</style>
<div id='searchformfix'>
<form action='/search' id='searchform'>
<input name='q' onblur='if (this.value == "") {this.value = "Search Videos...";}' onfocus='if (this.value == "Search Videos...") {this.value = "";}' type='text' value='Search Videos...'/></form>
<button class='fa fa-search' type='submit' value='Go'></button>
</div>
JsFiddle 演示:http://jsfiddle.net/jaribhai/wncwqerj/4/
所以这是一个有效的搜索栏。我想要做的是它在桌面设备中保持可见,并在像这样的移动设备中变得可扩展。
http://callmenick.com/_development/expanding-search-bar/
我认为如果不使用 Jquery 这是不可能的,所以有人告诉我如何才能实现此功能。
谢谢
一种方法是使用程式化的复选框来控制搜索输入的状态。
风格化带有关联标签的复选框以显示搜索图标。使用媒体查询并根据复选框的 :checked
状态显示或隐藏搜索输入。
演示 Fiddle:https://jsfiddle.net/abhitalks/ott3Lt78/
演示片段:
* { box-sizing: border-box; padding: 0; margin: 0; }
.srch { margin: 8px; }
.srch > label {
display: inline-block; text-align: center;
width: 32px; height: 32px; line-height: 32px;
background-color: #33d; color: #eee;
cursor: pointer; vertical-align: middle;
}
.srch > label+input { display: none; }
.srch > input[type=text] {
display: inline-block; height: 32px; width: 240px; padding: 4px;
border: 1px solid #33d; transition: width 0.5s;
}
@media screen and (max-width: 700px) {
.srch > input[type=text] {
width: 0; border-width: 0px; padding: 0px;
}
.srch > input[type=checkbox]:checked + input {
width: 240px; border-width: 1px; padding: 4px;
}
}
<div class="srch">
<label for='chk'>🔎</label>
<input id='chk' type='checkbox' />
<input type="text" placeholder="search videos" />
</div>
这是我的代码。
<style>
#searchformfix {
width: 50%;
border-right: 1px solid #E5E5E5;
border-left: 1px solid #E5E5E5;
position: relative;
background: #fff;
height: 40px;
display: inline-block;
border: 1px solid #219AEB;
border-radius: 5px;
margin-top: 5px;
}
#searchform {
margin: 0px 0 0;
padding: 0;
}
#searchform input[type="text"] {
background: #fff;
border: none;
float: left;
height: 100%;
transition: all 600ms cubic-bezier(0.215,0.61,0.355,1) 0s;
-moz-transition: all 300ms cubic-bezier(0.215,0.61,0.355,1) 0s;
-webkit-transition: all 600ms cubic-bezier(0.215,0.61,0.355,1) 0s;
-o-transition: all 600ms cubic-bezier(0.215,0.61,0.355,1) 0s;
color: #929292;
margin-left: 10px;
margin-top: 10px;
width: 80%;
}
button.fa.fa-search {
background: #FFF;
margin-top: 5px;
font-size: 24px;
float: right;
cursor: pointer;
}
</style>
<div id='searchformfix'>
<form action='/search' id='searchform'>
<input name='q' onblur='if (this.value == "") {this.value = "Search Videos...";}' onfocus='if (this.value == "Search Videos...") {this.value = "";}' type='text' value='Search Videos...'/></form>
<button class='fa fa-search' type='submit' value='Go'></button>
</div>
JsFiddle 演示:http://jsfiddle.net/jaribhai/wncwqerj/4/
所以这是一个有效的搜索栏。我想要做的是它在桌面设备中保持可见,并在像这样的移动设备中变得可扩展。
http://callmenick.com/_development/expanding-search-bar/
我认为如果不使用 Jquery 这是不可能的,所以有人告诉我如何才能实现此功能。 谢谢
一种方法是使用程式化的复选框来控制搜索输入的状态。
风格化带有关联标签的复选框以显示搜索图标。使用媒体查询并根据复选框的 :checked
状态显示或隐藏搜索输入。
演示 Fiddle:https://jsfiddle.net/abhitalks/ott3Lt78/
演示片段:
* { box-sizing: border-box; padding: 0; margin: 0; }
.srch { margin: 8px; }
.srch > label {
display: inline-block; text-align: center;
width: 32px; height: 32px; line-height: 32px;
background-color: #33d; color: #eee;
cursor: pointer; vertical-align: middle;
}
.srch > label+input { display: none; }
.srch > input[type=text] {
display: inline-block; height: 32px; width: 240px; padding: 4px;
border: 1px solid #33d; transition: width 0.5s;
}
@media screen and (max-width: 700px) {
.srch > input[type=text] {
width: 0; border-width: 0px; padding: 0px;
}
.srch > input[type=checkbox]:checked + input {
width: 240px; border-width: 1px; padding: 4px;
}
}
<div class="srch">
<label for='chk'>🔎</label>
<input id='chk' type='checkbox' />
<input type="text" placeholder="search videos" />
</div>