JS Input里添加小圖標的兩種方法
更新時間:2017年11月11日 13:28:21 作者:QunBinCheng
大家在做網(wǎng)站的時候,經(jīng)常需要在input里面添加小圖標功能,看似功能很簡單,但是實現(xiàn)起來還是有點技巧的,下面小編給大家介紹下JS Input里添加小圖標的兩種方法,需要的朋友參考下吧
我們在做網(wǎng)頁的時候,經(jīng)常需要在input里面添加小圖標,那么這里就介紹比較常見的兩種方法。
方法一
將小圖標當(dāng)做input的背景來插入,直接上代碼吧:
<style type="text/css">
*{
margin: 0;
padding: 0;
}
input{
border: none;
}
.box{
height: 50px;
background: yellow;
}
.box input{
width: 200px;
height: 30px;
border-radius: 15px;
margin: 10px 0;
background: url(image/search.gif) no-repeat;
background-color: white;
background-position: 3px;
padding-left: 30px;
border: 1px solid black;
outline: none;
}
</style>
</head>
<body>
<div class="box">
<input type="text" class="username" value="搜索"/>
</div>
</body>
方法二
使用 i 標簽插入
<style type="text/css">
*{
margin: 0;
padding: 0;
}
.box{
width: 200px;
position: relative;
}
.box .icon-search{
background: url(image/search.gif) no-repeat;
width: 20px;
height: 20px;
position: absolute;
top: 6px;
left: 0;
}
.box .username{
padding-left: 30px;
height: 25px;
}
</style>
</head>
<body>
<div class="box">
<i class="icon-search"></i>
<input type="text" class="username" value="搜索"/>
</div>
</body>
總結(jié)
以上所述是小編給大家介紹的JS Input里添加小圖標的兩種方法,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復(fù)大家的!
相關(guān)文章
HTML中的setCapture和releaseCapture使用介紹
setCapture函數(shù)的作用就是將后續(xù)的mouse事件都發(fā)送給這個對象,releaseCapture就是將鼠標事件還回去,由 document、window、object之類的自行來處理。這樣就保證了在拖動的過程中,不會由于經(jīng)過了其它的元素而受到干擾2012-03-03
談?wù)凧avaScript異步函數(shù)發(fā)展歷程
對大部分JavaScript開發(fā)者而言,async函數(shù)仍是新鮮事物,其發(fā)展經(jīng)歷了漫長的旅程。本文將梳理總結(jié)JavaScript異步函數(shù)的發(fā)展歷程,并表示未來async函數(shù)將成為實現(xiàn)異步的主要方式。2015-09-09
微信小程序跨頁面?zhèn)鬟fdata數(shù)據(jù)方法解析
這篇文章主要介紹了微信小程序跨頁面?zhèn)鬟fdata數(shù)據(jù)方法解析,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2019-12-12

