我知道这是一个老问题,但我在尝试解决同样的问题时遇到了它。我认为值得分享这个我在其他任何地方都找不到的解决方案。
基本上,解决方案是使用CSS来隐藏元素,并在其周围设置一个看起来像按钮的样式。单击“运行代码段”按钮以查看结果。<input>
<label>
我之前使用过JavaScript解决方案,效果也很好,但是仅使用CSS即可解决“演示”问题。
label.cameraButton {
display: inline-block;
margin: 1em 0;
/* Styles to make it look like a button */
padding: 0.5em;
border: 2px solid #666;
border-color: #EEE #CCC #CCC #EEE;
background-color: #DDD;
}
/* Look like a clicked/depressed button */
label.cameraButton:active {
border-color: #CCC #EEE #EEE #CCC;
}
/* This is the part that actually hides the 'Choose file' text box for camera inputs */
label.cameraButton input[accept*="camera"] {
display: none;
}
<!DOCTYPE html>
<html>
<head>
<title>Nice image capture button</title>
</head>
<body>
<label class="cameraButton">Take a picture
<input type="file" accept="image/*;capture=camera">
</label>
</body>
</html>