说明:传统的做法是给外部盒子relative定位,再给弹出框absolute定位,而这里我们将absolute独立使用

html

    <div class="search">
<ul id="result">
<li><a href="#">分享:CSS深入理解之float浮动</a></li>
<li><a href="#">案例:CSS圆角进化论</a></li>
<li><a href="#">案例:CSS Sprite雪碧图应用</a></li>
<li><a href="#">案例:CSS3 3D 特效</a></li>
</ul>
<input type="text" class="search-input" placeholder="课程搜索">
<a href="javascript:;" class="search-btn">搜索</a>
</div>

css

        .search{margin:20px;overflow:hidden;}
.search .search-input{width:200px;line-height:18px; padding:10px; margin:; border:0 none;font-size:12px;font-family:inherit; float: left; }
.search.focus{border-color: #2ea7e0; }
.search .search-input:focus{outline:0 none;}
.search .search-btn{width:38px;height:38px;float:left;background: url(images/search.png);text-indent:-9em;overflow:hidden; }
.search.focus .search-btn{background-position:0 -38px;}
#result{
display:none;
position:absolute;
width:260px;
margin:39px 0 0 -1px;
padding-left:;
list-style-type:none;
border:1px solid #e6e8e9;
background-color:#fff;
box-shadow:0px 1px 2px #d5d7d8;
font-size:12px;
}
#result>li{line-height:30px;padding-left:12px; }
#result>li:hover{background-color:#f9f9f9;}
#result a {display:block;color: #5e5e5e;text-decoration: none; }
#result a:hover {color:#000; }

javascript

(function() {
var input = document.getElementsByTagName("input")[0],
result = document.getElementById("result"); if (input && result) {
input.onfocus = function() {
this.parentNode.className = "search focus";
if (this.value !== "") {
result.style.display = "block";
}
};
input.onblur = function() {
if (this.value === "") {
this.parentNode.className = "search";
}
result.style.display = "none";
}; // IE7 that wrap a DIV for avoid bad effect from float
if (!document.querySelector) {
var div = document.createElement("div");
input.parentNode.insertBefore(div, input);
div.appendChild(result);
}
// events of datalist
if ("oninput" in input) {
input.addEventListener("input", function() {
if (this.value.trim() != "") {
result.style.display = "block";
} else {
result.style.display = "none";
}
});
} else {
// IE6-IE8
input.onpropertychange = function(event) {
event = event || window.event;
if (event.propertyName == "value" && /focus/.test(this.parentNode.className)) {
if (this.value != "") {
result.style.display = "block";
} else {
result.style.display = "none";
}
}
};
}
} })();

最新文章

  1. 搭建自己的Nuget服务器
  2. Module Zero之角色管理
  3. bootstrap 使用需注意的一些点
  4. 学习_单片机/嵌入式_的资源链接。——Arvin
  5. ASP.NET整理:Cookie,Application,Session,页面生命周期
  6. Codeforces 260 A - A. Laptops
  7. final运用于内部类访问局部变量
  8. CentOS安装中文输入法
  9. Eclipse编辑java文件报Unhandled event loop exception错误的解决办法
  10. MySQL查询过程中出现lost connection to mysql server during query 的解决办法
  11. MyTask2
  12. SQL Server 2008 定时作业的制定
  13. 创业类网站建设日志1——搭建服务器svn以及前端开发环境
  14. spring aop + xmemcached 配置service层缓存策略
  15. 移动端touch事件实现页面弹动--小插件
  16. 记录maven的一些命令
  17. Android数据库Sqlite-android学习之旅(九)
  18. 乐观锁机制解决多层嵌套异步ajax问题
  19. SPOJ RPLN (模板题)(ST算法)【RMQ】
  20. NOIP国王游戏

热门文章

  1. Jquery常用方法篇(一)
  2. android httpClient 支持HTTPS的2种处理方式
  3. SqlServer表中两条全然同样的记录,怎样删除当中1条
  4. spring mvc[转]
  5. Hash表
  6. URI URL
  7. 实现当UILable的内容超出其范围后自动滚动效果
  8. Http协议三次握手过程
  9. 编译LFS
  10. 通过文件读写方式实现Matlab和Modelsim的联合仿真