【问题标题】:Search Bar Visible In Desktop And Expandable In Mobile Devices搜索栏在桌面上可见,在移动设备中可扩展
【发布时间】:2016-01-08 16:51:46
【问题描述】:

这是我的代码。

<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 == &quot;&quot;) {this.value = &quot;Search Videos...&quot;;}' onfocus='if (this.value == &quot;Search Videos...&quot;) {this.value = &quot;&quot;;}' 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 这是不可能的,所以有人告诉我如何才能获得这个功能。 谢谢

【问题讨论】:

    标签: javascript jquery css searchbar


    【解决方案1】:

    一种方法是使用风格化的复选框来控制搜索输入的状态。

    样式化带有关联标签的复选框以显示搜索图标。使用媒体查询并根据复选框的:checked 状态显示或隐藏搜索输入。

    演示小提琴: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'>&#128270;</label>
      <input id='chk' type='checkbox' />
      <input type="text" placeholder="search videos" />
    </div>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-04
      • 2018-08-20
      • 2019-09-30
      • 1970-01-01
      • 2020-06-06
      • 2019-05-17
      相关资源
      最近更新 更多