简体   繁体   English

用图像图标替换文件字段 - HTML / CSS

[英]Replace File Field with Image Icon - HTML/CSS

I want to replace my File Field with Image Icon. 我想用图像图标替换我的文件字段 Because File Field Doesn't looks cool. 因为文件字段看起来不酷。

Take a Look at this Camera Icon. 看看这个相机图标。 When someone clicks this Icon, Browse Window Opened up : 当有人单击此图标时,浏览窗口打开: 在此输入图像描述

Here is JsFiddle DEMO: http://jsfiddle.net/8aJb4/2/ 这是JsFiddle DEMO: http //jsfiddle.net/8aJb4/2/

Here is my CODE: 这是我的代码:

HTML: HTML:

<div class="container">
    <input type="file" name="image_src" id="image_src" >
</div>

CSS: CSS:

.container{
    width:500px;
    border:black solid 1px;
    text-align:center;
    padding:4px;

}

Here is the link to Image Icon: http://postimg.org/image/rg17ffpxh/ 这是图像图标的链接: http //postimg.org/image/rg17ffpxh/

Here's a Fiddle 这是一个小提琴

<div class="container">
  <span class="select-wrapper">
    <input type="file" name="image_src" id="image_src" />
  </span>
</div>


.container{
  width: 500px;
  border: 1px solid #333;
  padding: 4px;
}
.select-wrapper {
  background: url(http://s10.postimg.org/4rc0fv8jt/camera.png) no-repeat;
  background-size: cover;
  display: block;
  position: relative;
  width: 33px;
  height: 26px;
}
#image_src {
  width: 26px;
  height: 26px;
  margin-right: 100px;
  opacity: 0;
  filter: alpha(opacity=0); /* IE 5-7 */
}

HTML HTML

 <script>
function upload(){
  document.getElementById("image_src").click();
 }
 </script>
<div class="container">
    <img id="img" src="http://postimg.org/image/rg17ffpxh/" onclick="upload()" alt="hello"/>
   <input type="file" name="image_src" id="image_src" />
   </div>

CSS CSS

.container{
width:500px;
border:black solid 1px;
text-align:center;
padding:4px;   
}
#image_src {
position:absolute;
left:-9999px;
}
#img { cursor:pointer; }

I didn't get your image link to work but here is jsfiddle 我没有让你的图像链接工作,但这里是jsfiddle

it is simple, you just define a file element as hidden and also define an img tag with your own background in it. 它很简单,您只需将文件元素定义为隐藏,并定义一个带有您自己背景的img标记。 Write javascript to click the file element programmatically on the click of your img tag. 编写javascript,点击你的img标签,以编程方式点击文件元素。 something like this: 这样的事情:

<input type="file" name="image_src" id="image_src" hidden='hidden'>
<img src='url' onclick='openWindow()'>

function openWindow(){
document.getElementById("image_src").click
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM