说明:传统的做法是给外部盒子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";
}
}
};
}
} })();

absolute独立使用之下拉框最佳实践的更多相关文章

  1. ASP.NET MVC之下拉框绑定四种方式(十)

    前言 上两节我们讲了文件上传的问题,关于这个上传的问题还未结束,我也在花时间做做分割大文件处理以及显示进度的问题,到时完成的话再发表,为了不耽误学习MVC其他内容的计划,我们今天开始好好讲讲关于MVC ...

  2. yii2组件之下拉框带搜索功能(yii-select2)

    简单的小功能,但是用起来还是蛮爽的.分享出来让更多的人有更快的开发效率,开开心心快乐编程. 如果你还没有使用过composer,你可就out了,看我的教程分享,composer简直就是必备神奇有木有. ...

  3. 转:python webdriver API 之下拉框处理

    下拉框也是 web 页面上非常常见的功能,webdriver 对于一般的下拉框处理起来也相当简单,要想定位下拉框中的内容,首先需要定位到下拉框:这样的二次定位,我们在前面的例子中已经有过使用,下面通过 ...

  4. thymeleaf之下拉框回显选中

    #1.select下拉框取值    <div class="form-group ">        <label id="resource" ...

  5. 插件之下拉框Select2

    select2为代替常规的select而出现,可自定义select的样式,最明显的功能就是集合中可以搜索 关于浏览器要求,ie8+,Chrome 8+,Firefox 10+,Safari 3+,Op ...

  6. 【Python+selenium Wendriver API】之下拉框定位

    上代码: # coding:utf-8 from selenium import webdriver from selenium.webdriver.common.action_chains impo ...

  7. Python自动化之下拉框,隐藏标签定位 代码&报错解决

    python自动化:下拉框定位方法之select标签  style="display: none;" 报错 selenium.common.exceptions.ElementNo ...

  8. Selenium之下拉框操作

    下拉框操作: 一般下拉框适用场景:在新增时有下拉框选项,在二级联动或多级联动有下拉(比如:在选择省市县时的多级联动下拉). 下拉框选择都有select的标签属性,存在两个属性select和option ...

  9. (十一)easyUI之下拉框

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

随机推荐

  1. poj 1273 Drainage Ditches【最大流入门】

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 63924   Accepted: 2467 ...

  2. UVA Knight Moves

    题目例如以下: Knight Moves  A friend of you is doing research on the Traveling Knight Problem (TKP) where ...

  3. 安装Rational Rose启动报错:无法启动此程序,由于计算机中丢失 suite objects.dll。

    执行Rational Rose的时候假设出现这种错误,先检查环境变量有没有common的地址,假设没有直接配上就OK:配置例如以下:D:\Program Files\Rational\Common; ...

  4. [Javascript] Drawing Paths - Lines and Rectangles

    <!DOCTYPE html> <html> <head> <meta name="description" content=" ...

  5. 理解URI和URL

    1)定义: URI: Uniform Resource Identifier,通用资源标识符 ---是一个用于标识某一互联网资源名称的字符串(by 维基百科) URL:Uniform Resource ...

  6. Android(java)学习笔记160:Framework运行环境之 Android进程产生过程

    1.前面Android(java)学习笔记159提到Dalvik虚拟机启动初始化过程,就下来就是启动zygote进程: zygote进程是所有APK应用进程的父进程:每当执行一个Android应用程序 ...

  7. 文件处理-Directory类 (C#)

    转http://skybirdzw.blog.163.com/blog/static/7257062620099751329403/ 文件处理-Directory类 (C#) Directory.Cr ...

  8. HINSTANCE数据类型

    作者:马 岩(Furzoom) (http://www.cnblogs.com/furzoom/)版权声明:本文的版权归作者与博客园共同所有.转载时请在明显地方注明本文的详细链接,未经作者同意请不要删 ...

  9. linux部署tomcat

    安装说明 安装环境:CentOS-6.5安装方式:源码安装 软件:apache-tomcat-6.0.45.tar.gz下载地址:http://tomcat.apache.org/download-6 ...

  10. 解决在mybatis中使用CTE进行oracle查询数据类型为long的字段出现流关闭问题

    今天把notice表中的content字段改为long字段后,含有该字段的使用CTE的查询语句报错了.提示一下错误 ### Cause: java.sql.SQLException: 流已被关闭 ; ...