前端应用之自定义搜索框实现

定义一个前端div

<div class="site-search"> <div id="search"> <input type="text" name="s" class="text" placeholder="输入关键字搜索" /> <button type="button" onclick="javascript:doSearch();" class="submit">搜索</button> </div> </div>

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

关键代码,样式调整

.site-search{
	width:25%;
	float:right;
	width:250px;
	height:50px;
}
#search{
	position:relative;
	margin-top:15px;
}
#search input{
	padding-right:30px;
}
#search button{
	position:absolute;
	right:4px;
	top:2px;
	border:none;
	padding:0;
	width:24px;
	height:24px;
	background:url("static/images/search.png") no-repeat scroll right center transparent;
	direction:ltr;
	text-indent:-9999em;
}

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

实现效果
在这里插入图片描述

项目全部代码在自己的开源项目:https://github.com/u014427391/myblog

文章来源: smilenicky.blog.csdn.net,作者:smileNicky,版权归原作者所有,如需转载,请联系作者。

原文链接:smilenicky.blog.csdn.net/article/details/87897750

(完)