1

I am making a react app where I need to click an image which will serve the purpose of a button to upload a file. I can not figure out how to use an image as an input button.

1
  • 1
    @StudioTime . That doesnt refer to the question, as this question is about a submit button (Which needs a form) Commented Nov 23, 2021 at 11:58

1 Answer 1

4

Probably the easiest way would be to use a wrapper element and pure css for that. just put an image where the text is now.

.wrapper{
  display:inline-block;
  position:relative
}

.btnimg{
  background:red;
  pointer-events:none;
  width:250px;
  height:90px;
  opacity:1;
  line-height:90px;
  text-align:center;
}

input[type=file]{
  opacity:0;
  position:absolute;
  top:0;
  left:0;
  right:0;
  bottom:0;
}
<div class="wrapper">
<div class="btnimg">btn with image</div>
<input type="file">
</div>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.