漂亮select框

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
	<style type="text/css">
		.selectPage{ 
			width:107px;
			height:21px;
			background:none;
			border:none;
			padding-top:3px;
			background-color:Transparent;
			color:gray;
			position:absolute;
			z-index:-1;
		}
		#sleHid{ 
			display:block; 
			width:109px; 
			height:21px; 
			overflow:hidden;
			position:relative; /*解决IE6、7兼容问题*/
			top:2px;  /*解决IE6、7兼容问题*/
			left:2px;  /*解决IE6、7兼容问题*/
			z-index:80;
		}     
		#sleBG{
			width:111px; 
			height:24px;
			background:url(每页显示条数.png) no-repeat;
			display:inline-block;
			height:24px;
			position:relative;
			z-index:90;
		} 
		#seleDIV{
			margin-top:-16px;
			margin-left:93px;
			position:absolute;
			z-index:100;
		}
	</style>
	
	</head>

	<body>
	
		<span id="sleBG">
		   <span id="sleHid">
			 <select name="select" size="1" id="select" class="selectPage">
			   <option  value="张三">     张三</option>
			   <option  value="李四">     李四</option>
			 </select>
		   </span>
		   <div id="seleDIV"><img src="selsan.png"/></div>
		</span>
	</body>

</html>



<span style="color: rgb(51, 51, 51); font-family: verdana, 微软雅黑, sans-serif; font-size: 14px; line-height: 25.200000762939453px;">解释一下:</span><br class="edui-filter-align-left" style="color: rgb(51, 51, 51); font-family: verdana, 微软雅黑, sans-serif; font-size: 14px; line-height: 25.200000762939453px;" /><span style="color: rgb(51, 51, 51); font-family: verdana, 微软雅黑, sans-serif; font-size: 14px; line-height: 25.200000762939453px;">原理是在select外层加入2个span,首先设置第一个span,其width大于select的width,在这个span的背景加入我们想要的下拉箭头样式,然后再加第二个span,其width小于select的width,关键设置好它的overflow的宽度,隐藏select的下拉箭头。</span><br class="edui-filter-align-left" style="color: rgb(51, 51, 51); font-family: verdana, 微软雅黑, sans-serif; font-size: 14px; line-height: 25.200000762939453px;" /><span style="color: rgb(51, 51, 51); font-family: verdana, 微软雅黑, sans-serif; font-size: 14px; line-height: 25.200000762939453px;">优点是设置简单,缺点是若无javascript模拟鼠标点击则下拉箭头仅能起到装饰作用。</span><br class="edui-filter-align-left" style="color: rgb(51, 51, 51); font-family: verdana, 微软雅黑, sans-serif; font-size: 14px; line-height: 25.200000762939453px;" /><span style="color: rgb(51, 51, 51); font-family: verdana, 微软雅黑, sans-serif; font-size: 14px; line-height: 25.200000762939453px;">想要求漂亮而且代码的少的话,可以使用本方法。</span><br class="edui-filter-align-left" style="color: rgb(51, 51, 51); font-family: verdana, 微软雅黑, sans-serif; font-size: 14px; line-height: 25.200000762939453px;" /><span style="color: rgb(51, 51, 51); font-family: verdana, 微软雅黑, sans-serif; font-size: 14px; line-height: 25.200000762939453px;">注释:</span><br class="edui-filter-align-left" style="color: rgb(51, 51, 51); font-family: verdana, 微软雅黑, sans-serif; font-size: 14px; line-height: 25.200000762939453px;" /><span style="color: rgb(51, 51, 51); font-family: verdana, 微软雅黑, sans-serif; font-size: 14px; line-height: 25.200000762939453px;">当我们使用overflow:hidden;后,你会发现,这个属性只在FF和IE8下起作用,那么在IE6、7下怎么办?很简单,加一个position:relative;即可。然后根据你需要的位置,加一个top、left,问题完美解决。</span>

            


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值