- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
如果您在桌面/PC 上访问某人的 instagram 页面,单击搜索栏时,它会向左浮动,然后可以输入文本进行搜索。当搜索字段中没有文本时,搜索图标和“搜索”占位符会回到原来的中心位置。
我假设 javacript/jquery 用于此,我也想实现它,但我不知道有任何脚本可以完成此操作。下面是我的 HTML 和 CSS 代码,任何帮助将不胜感激!
HTML
<div class="box">
<div class="container-1">
<span class="icon"><i class="fa fa-search"></i></span>
<input type="search" id="search" placeholder="Search" />
</div>
</div>
CSS
.box{
margin: 3px auto;
width: 200px;
height: 20px;
padding-right: 10px;
}
.container-1{
width: 200px;
vertical-align: middle;
white-space: nowrap;
position: relative;
}
.container-1 input#search{
width: 200px;
height: 30px;
background: #FFFFFF;
border: 1px solid #C5C4C4;
font-size: 10pt;
text-align: center;
color: #000000;
-webkit-border-radius: 25px;
-moz-border-radius: 25px;
border-radius: 25px;
-webkit-transition: background .55s ease;
-moz-transition: background .55s ease;
-ms-transition: background .55s ease;
-o-transition: background .55s ease;
transition: background .55s ease;
}
.container-1 input#search::-webkit-input-placeholder {
color: #A8A7A7;
letter-spacing: 1px;
font-size: 12px;
}
.container-1 input#search:-moz-placeholder { /* Firefox 18- */
color: #A8A7A7;
letter-spacing: 1px;
font-size: 12px;
}
.container-1 input#search::-moz-placeholder { /* Firefox 19+ */
color: #A8A7A7;
letter-spacing: 1px;
font-size: 12px;
}
.container-1 input#search:-ms-input-placeholder {
color: #A8A7A7;
letter-spacing: 1px;
font-size: 12px;
}
input:focus::-webkit-input-placeholder { color:transparent; }
input:focus:-moz-placeholder { color:transparent; } /* Firefox 18- */
input:focus::-moz-placeholder { color:transparent; } /* Firefox 19+ */
input:focus:-ms-input-placeholder { color:transparent; } /* oldIE ;) */
.container-1 .icon{
position: absolute;
padding-top: 8px;
padding-left: 50px;
font-size: 12px;
z-index: 1;
color: #A8A7A7;
}
.container-1 input#search:hover, .container-1 input#search:focus, .container-1 input#search:active{
outline:none;
background: #ffffff;
}
input::-webkit-search-decoration,
input::-webkit-search-cancel-button {
display: none;
}
@media all and (max-width : 370px) {
.box{
margin: 15px auto;
width: 200px;
height: 20px;
padding-right: 10px;
}
}
最佳答案
我创建了一个简单的 fiddle ,让您了解如何完成它。现在我不知道如何使占位符居中,所以它是固定填充的。
input {
width: 200px;
padding-left: 80px;
box-sizing: border-box;
background: url(https://cdn3.iconfinder.com/data/icons/google-material-design-icons/48/ic_search_48px-128.png);
background-size: 16px;
background-repeat: no-repeat;
background-position: 62px 0;
}
input:focus {
padding-left: 16px;
background-position: 0;
}
<input type="text" placeholder="Search" />
附言您可以通过提供过渡来轻松地为这种效果设置动画,例如:
transition: all 0.05s ease-in-out;
它应该是这样的:
input {
width: 200px;
padding-left: 80px;
box-sizing: border-box;
background: url(https://cdn3.iconfinder.com/data/icons/google-material-design-icons/48/ic_search_48px-128.png);
background-size: 16px;
background-repeat: no-repeat;
background-position: 62px 0;
transition: all 0.05s ease-in-out;
}
input:focus {
padding-left: 16px;
background-position: 0;
}
<input type="text" placeholder="Search" />
(来自 www.iconfinder.com 的搜索图标)
关于jquery - 受 Instagram 网络/桌面启发的搜索框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39212261/
我正在尝试构建一个 float 在 ViewController 顶部的按钮,它应该静态地保持在相同的位置,而它下面的 viewcontroller 可以上下滚动。 我设计了自己的按钮类,在父 Vie
目前Boost有hash_combine函数输出32位无符号整数(准确的说是size_t)。一些引用: http://www.boost.org/doc/libs/1_43_0/doc/html/ha
我试过看看如果我们尝试以与 Java 中类似的方式“破坏”一个对象数组,在 C++ 中会发生什么。 在 Java 中我们可以有一个 Double[] 类型的数组,例如,将其向上转换为 Number[]
很抱歉问了这么长的问题,但我需要做一个介绍以使其更清楚。 我需要一些代码来在我的 Headers 组件之间切换 和 . 起初我使用 CSS 媒体查询通过 display: block | none;
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 5 年前。 Improve
我是一名优秀的程序员,十分优秀!