Reputation: 153
I want the input="file"
to be hidden and style the input="file"
with icon and clicking upon the icon to select image.
.cover_photo {width:100%; height:250px; overflow:hidden; position:relative;}
.cover_photo img {width:100%;}
.upload_btn { position:absolute; top:0; left:0;}
.upload_btn input[type="file"] {display:none;}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<section>
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="cover_photo">
<img class="img-responsive" src="http://underafricanskiessafaris.co.za/wp-content/uploads/2015/02/BG-1.jpg" />
<div class="upload_btn">
<form>
<i id="icon_upload" class="fa fa-camera"></i>
<input type="file" name="cover-photo" id="icon_upload" />
</form>
</div>
</div>
</div>
</div>
</div>
</section>
Upvotes: 7
Views: 13114
Reputation: 169
Give the input a name and hide it with CSS <input style="display:none" class="hidden" type="file" capture="camera" accept="image/*" multiple #cameraInput id="cameraInput" name="cameraInput">
Then create a button which holds your nice photo (material symbol in this example) and use script to call click() on the cameraInput <button type="button" (click)="cameraInput.click()"> photo_camera
Upvotes: 0
Reputation: 166
.image{
cursor:pointer;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet"/>
<label class="image" for="image-id"><i class="fa-regular fa-image"></i></label>
<input type="file" class="image" id="image-id" multiple accept="image/*" hidden>
Upvotes: 0
Reputation: 3917
I think you want something like this.Place an icon and clicking on the icon, programmatically click the input type file.
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<input type="file" id="file_upload_id" style="display:none">
<label>Upload:</label> <a href="#"><i id="icon_upload" class="fa fa-upload" onclick="_upload()"></i></a>
<script>
function _upload(){
document.getElementById('file_upload_id').click();
}
</script>
Upvotes: 2
Reputation: 6328
Used opacity: 0
to hide the file input and make it position: absolute
.cover_photo {
width:100%;
height:250px;
overflow:hidden;
position:relative;
}
.cover_photo img {
width:100%;
}
.upload_btn {
position:absolute;
top:0;
left:0;
}
.upload_btn input[type="file"] {
height: 28px;
left: 0;
position: absolute;
top: 0;
opacity: 0;
width: 32px;
z-index: 1;
}
#icon_upload {
font-size:30px;
cursor: pointer;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<section>
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="cover_photo">
<img class="img-responsive" src="http://underafricanskiessafaris.co.za/wp-content/uploads/2015/02/BG-1.jpg" />
<div class="upload_btn">
<form>
<i id="icon_upload" class="fa fa-camera"></i>
<input type="file" name="cover-photo" id="icon_upload" />
</form>
</div>
</div>
</div>
</div>
</div>
</section>
Upvotes: 0
Reputation: 1454
With label
#fileInput{
display: none;
}
#icon{
width: 100px;
cursor: pointer;
}
<label for="fileInput">
<img id="icon" src="https://image.freepik.com/free-icon/upload-arrow_318-26670.jpg">
</label>
<input id="fileInput" type="file">
Upvotes: 19
Reputation: 922
You can use for label and put the image inside instead of text, then design it what ever you want.
<div>
<label for="browse"><img src="img/0.jpg" /></label>
<input type="file" id="browse" name="browse" style="display: none">
</div>
Upvotes: 1