gpt4 book ai didi

jquery - 受 Instagram 网络/桌面启发的搜索框

转载 作者:太空宇宙 更新时间:2023-11-04 09:49:35 29 4
gpt4 key购买 nike

如果您在桌面/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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com