关于修改 标签input file 样式问题!

正常的input file 标签长不是很好看 !所以一般会进行修饰!

git地址DEMO

修饰方法也就是用另一个好看标签来压住它!看代码

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style>
		*{
			margin: 0;
			padding: 0;
		}
		.box{
			width: 110px;
			height: 34px;
			margin: 100px auto;
			position: relative;
		}
		.box a{
			display: block;
			width: 110px;
			height: 34px;
			position: absolute;
			left: 0;
			top: 0;
			background: green;
			text-decoration: none;
			color: #fff;
			border-radius: 5px;
			text-align: center;
			line-height: 34px;
		}
		.box input{
			opacity:0;
		}

	</style>
</head>
<body>
	<div class="box">
		<a href="javascript:;">获取文件</a>
		<input type="file" />
	</div>
	

</body>
</html>
但是!虽然这样实现了样式修改,还是有一点小瑕疵!那就是鼠标在a标签的不同位置会有两种样式 箭头样式与手指样式! 正常情况下使用css{cursor:pointer;}这个属性可以修改鼠标的样式 !但是对于file标签来说是行不通的!

解决方法1:使用direction: rtl;这个属性可以指定内容书写方向!将input标签添加此属性,反转其内容,这样整个a标签都回变为手指形状,并且不影响file的功能!如果不要求兼容ie的话这个也可以了!

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style>
		*{
			margin: 0;
			padding: 0;
		}
		.box{
			width: 110px;
			height: 34px;
			margin: 100px auto;
			position: relative;
			overflow: hidden;
		}
		.box a{
			display: block;
			width: 110px;
			height: 34px;
			position: absolute;
			left: 0;
			top: 0;
			background: green;
			text-decoration: none;
			color: #fff;
			border-radius: 5px;
			text-align: center;
			line-height: 34px;
		}
		.box input{
			width: 180px;
			height: 34px;
			opacity:0;
			direction: rtl;
			cursor:pointer;
		}

	</style>
</head>
<body>
	<div class="box">
		<a href="javascript:;">获取文件</a>
		<input type="file" />
	</div>
	

</body>
</html>

上边的方法测试了下在IE下文字会跑偏!所以还有一个用position来解决!代码如下,去掉反转input样式,利用定位拉长input距离 使鼠标点击距离刚好点击文字的中部!这样就避免了iE下的怪异现象。

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style>
		*{
			margin: 0;
			padding: 0;
		}
		.box{
			width: 110px;
			height: 34px;
			margin: 100px auto;
			position: relative;
			overflow: hidden;
		}
		.box a{
			display: block;
			width: 110px;
			height: 34px;
			position: absolute;
			left: 0;
			top: 0;
			background: green;
			text-decoration: none;
			color: #fff;
			border-radius: 5px;
			text-align: center;
			line-height: 34px;
		}
		.box input{
			width: 180px;
			height: 34px;
			opacity:0;
			position: absolute;
			left: -80px;
			top: 0;
			cursor:pointer;
			
		
		}

	</style>
</head>
<body>
	<div class="box">
		<a href="javascript:;">获取文件</a>
		<input type="file" />
	</div>
</body>
</html>





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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值