光标:指针属性不适用于 Webkit 浏览器中的文件上传按钮
我的 CSS 代码在 webkit 浏览器(如 safari 和 chrome)上不起作用,
如果你想要现场示例,它是 http ://jsfiddle.net/mnjKX/1/
我有这个CSS代码
.file-wrapper {
cursor: pointer;
display: inline-block;
overflow: hidden;
position: relative;
}
.file-wrapper input {
cursor: pointer;
font-size: 100px;
height: 100%;
filter: alpha(opacity=1);
-moz-opacity: 0.01;
opacity: 0.01;
position: absolute;
right: 0;
top: 0;
}
.file-wrapper .button {
background: #79130e;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
color: #fff;
cursor: pointer;
display: inline-block;
font-size: 11px;
font-weight: bold;
margin-right: 5px;
padding: 4px 18px;
text-transform: uppercase;
}
和这个HTML代码:
<span class="file-wrapper">
<input type="file" name="photo" id="photo" />
<span class="button">Choose a Photo</span>
</span>
这个代码显示隐藏的输入文件标签, 这里的问题是光标:指针在 webkit 浏览器上不起作用,
我该如何解决它或绕过/超越这个问题?
i have CSS code that does not really work on webkit browsers such as safari and chrome
if you want live example here it is http://jsfiddle.net/mnjKX/1/
i have this CSS code
.file-wrapper {
cursor: pointer;
display: inline-block;
overflow: hidden;
position: relative;
}
.file-wrapper input {
cursor: pointer;
font-size: 100px;
height: 100%;
filter: alpha(opacity=1);
-moz-opacity: 0.01;
opacity: 0.01;
position: absolute;
right: 0;
top: 0;
}
.file-wrapper .button {
background: #79130e;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
color: #fff;
cursor: pointer;
display: inline-block;
font-size: 11px;
font-weight: bold;
margin-right: 5px;
padding: 4px 18px;
text-transform: uppercase;
}
and this HTML code :
<span class="file-wrapper">
<input type="file" name="photo" id="photo" />
<span class="button">Choose a Photo</span>
</span>
this code shows hidden input file tag ,
the problem here is that the cursor:pointer is does not work on webkit browsers ,
how can i solve it or bypass / overtake this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于初学者来说,如果您从
input
规则中删除height
声明,它就可以在 Chrome 中运行。现场演示: http://jsfiddle.net/mnjKX/16/
但这个透明的输入字段是一个地狱般的黑客......我不会依赖它。
更新:
这是正确的解决方案:
我认为文件上传按钮无法访问,但 Chrome 的用户代理样式表证明了我的错误
:)
For starters, it works in Chrome if you remove the
height
declaration from theinput
rule.Live demo: http://jsfiddle.net/mnjKX/16/
But this transparent input field is a hell of a hack... I wouldn't rely on it.
Update:
And here is the proper solution:
I thought the file upload button is unreachable, but Chrome's user agent style sheet proved my wrong
:)
我想出了一个有趣的(跨浏览器)解决方案:
给输入一个 CSS 属性cursor:pointer,将输入放在一个 div 中(带有溢出:隐藏)并给输入一个 100% 的左填充。填充区域将具有指针属性。
我个人不信任 -webkit 和 -moz 修复,因为我觉得它们是任意的和临时的,并且很快就会被替换。
An interesting (cross-browser) solution I came up with:
Give the input a CSS property of cursor:pointer, place the input in a div (with overflow:hidden) and give the input a left padding of 100%. The padded area will have the pointer property.
I personally don't trust -webkit and -moz fixes because I feel like they are arbitrary and temporary, and will be replaced soon.
光标:指针在输入文件上不起作用只是因为默认按钮。这里没有什么特别的原因。您需要通过此代码删除其外观,注意 font-size:0。
对我来说,它在 Chrome、Firefox 和 IE 上完美运行。我希望,这也会对您有所帮助。
cursor:pointer does not work on input file just because of the default button. No special reason here. You need to remove its appearance via this code, pay attention with font-size:0.
It works perfectly on Chrome, Firefox and IE for me. I hope, this will also help you.