自定义文件输入样式

如果您对Webkit / Blink / Chrome特定的样式感兴趣,可以隐藏一个专有的伪元素,然后使用非标准的psudeo-on-an-input输入:

<input type="file" class="custom-file-input">
.custom-file-input::-webkit-file-upload-button {
  visibility: hidden;
}
.custom-file-input::before {
  content: 'Select some files';
  display: inline-block;
  background: linear-gradient(top, #f9f9f9, #e3e3e3);
  border: 1px solid #999;
  border-radius: 3px;
  padding: 5px 8px;
  outline: none;
  white-space: nowrap;
  -webkit-user-select: none;
  cursor: pointer;
  text-shadow: 1px 1px #fff;
  font-weight: 700;
  font-size: 10pt;
}
.custom-file-input:hover::before {
  border-color: black;
}
.custom-file-input:active::before {
  background: -webkit-linear-gradient(top, #e3e3e3, #f9f9f9);
}

演示版

CodePen查看 Chris Coyier@chriscoyier在WebKit / Blink中的笔自定义文件输入

合理的警告:它不会显示所选的文件名,但是您可以对其进行调整。 我发现这些天通常会在选择文件后触发事件,并以这种方式捕获数据。

WTF表格

总是值得一试的是WTF的形式也是这样做的:

参见Chris Coyier@chriscoyier )在CodePen从WTF表单输入的笔文件

翻译自: https://css-tricks.com/snippets/css/custom-file-input-styling-webkitblink/

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值