What are some ways to customize the appearance of the file input element?

I am currently working with MVC 5 and bootstrap. Can someone assist me in customizing the input type file element to match the design shown in the image below?

.file-uploader .input-group input, .file-uploader .input-group-btn .button {
  height: 35px;
}
.file-uploader .input-group .input-group-addon {
    padding: 2px 15px;
    font-size: 15px;
    font-weight: normal;
    line-height: 1;
    color: #337ab7;
    text-align: center;
    background-color: #fff;
    border: 1px solid #d6d9e2;
    border-radius: 0;
}
<div class="form-group">
                                                        <label for="exampleInputEmail1">Logo image</label>
                                                        <div class="form-group file-uploader">
                                                            <input type="file" name="img[]" class="file">
                                                            <div class="input-group col-xs-12">
                                                                <span class="input-group-addon"><i class="glyphicon glyphicon-picture"></i></span>
                                                                <input type="text" class="form-control input-lg" disabled placeholder="Upload Image">
                                                                <span class="input-group-btn">
                                                                    <button class="browse btn btn-primary" type="button"><i class="glyphicon glyphicon-search"></i>Browse</button> 
                                                                </span>
                                                            </div>
                                                        </div>
                                                    </div>

Seeking assistance from experienced developers...

Answer №1

.upload-section .input-group input,
.file-uploader .input-group-btn .button {
  height: 35px;
}
.upload-section .input-group .input-group-addon {
  padding: 2px 15px;
  font-size: 15px;
  font-weight: normal;
  line-height: 1;
  color: #337ab7;
  text-align: center;
  background-color: #fff;
  border: 1px solid #d6d9e2;
  border-radius: 0;
}
.image-upload
{
  position: absolute;
  top: 0;
  left: 0;
  opacity: 0;
  width:100%;
  height:100%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
<div class="form-group">
  <label for="exampleInputEmail1">Profile Picture</label>
  <div class="form-group upload-section">
    
    <div class="input-group col-xs-12">
      <span class="input-group-addon"><i class="glyphicon glyphicon-camera"></i></span>
      <input type="text" class="form-control input-lg" disabled placeholder="Choose Image">
      <span class="input-group-btn">
        <div class="browse btn btn-primary"><i class="glyphicon glyphicon-folder-open"></i> Browse<input type="file" name="image[]" class="image-upload"></div> 
      </span>
    </div>
  </div>
</div>

Answer №2

I implemented a few lines of JavaScript code to enhance the effect. Give it a try.

var button = document.getElementById('search');
var file = document.getElementById('hideFile');
var output = document.getElementById('output');

button.addEventListener('click',function(){
  file.click();
});

file.addEventListener('change',function(event){
  var f = event.target.files;
  if(!f.length) {
    output.innerHTML = "Upload Image";
    output.title = "";
    return;
  } else {
    output.innerHTML = "";    
    }
  var fileList = "";
  for(var i=0;i<f.length;i++){
    fileList += f[i].name;
    if(i<f.length-1) fileList += ", ";
  }
  output.innerHTML = fileList;
  output.title = fileList;
});
#search{
  border: solid 0px #33aaff;
  margin:10px;
  outline:0;
  background-color:transparent;
  display:block;
  height:30px;
  padding:0px;
}
#hideFile{
  display:none !important;
}

#search *{
  float:left;
  display:block;
  height:100%;
  border: solid 1px #cccccc;
  line-height:28px !important;
  top:0px !important;
  padding: 0 15px;
  vertical-align:middle !important;
}

#search span:nth-child(1){
  color:#4371B3 !important;
  
}
#search span:nth-child(2){
  width:200px;
  background-color:#eee;
  color:#aaa;
  white-space:nowrap;
  overflow:hidden;
}
#search span:nth-child(3){
  background-color:#4371B3;
  color:white !important;
  border-radius:0 6px 6px 0;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<button id="search">
  <span class="glyphicon glyphicon-picture"></span>
  <span id="output">Upload Image</span>
  <span class="glyphicon glyphicon-search">Browse</span>
  <input id="hideFile" type="file" multiple/>
</button>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Hold off on showing the image until it has finished loading

// Here's the code snippet angular .module('imgapp', []) .controller('mainCtrl', mainCtrl); function mainCtrl() { var vm = this; vm.first = { title: 'Image 1', url: 'http://www.image-mapper.com ...

Hide programmer's comments from public view using personalized PHP scripts

When developing a HTML page, comments such as <!-- Comment 1 --> or within PHP // Comment2 can be easily viewed by right-clicking and selecting "Show code". Is there a way to prevent this from happening? ...

Guide on showcasing MYSQL table columns in an arranged CSS block layout!

I am trying to format table columns using a CSS display:block style. I want the final result to resemble the table displayed in the image below: https://example.com/table_image.png Currently, I am utilizing MYSQL and PHP to showcase the columns of the ta ...

Leverage the power of JavaScript by combining it with the .on and .editableselect methods

I am facing an issue with a select input that I am trying to make both editable and trigger an ajax request using the on change JS function. However, only one of the functions is working as expected because I have used the same id for the select input twic ...

What are the essential files needed in Kendo UI Core for a mobile app?

Several months ago, I created a trial Kendo mobile app but now I want to verify it using the most recent version of Kendo UI Core. In my previous project, I referenced the following files: <link href="../styles/kendo.common.min.css" rel="stylesheet" / ...

It is impossible to add a new element between two existing elements that share the same parent

I'm attempting to place an <hr> tag between the first and second .field-container. Because they have the same parent, I thought using element1.parentNode.insertBefore(element2, ...) would be the solution. However, it is not working as expected a ...

Is there a way to integrate the distanceTo function from Leaflet into my own custom library that I am planning to develop?

I am currently incorporating leaflet into my project and I have encountered the distanceTo method which calculates the distance between two coordinates. My goal is to create a separate JS file with a function named getDistance() where I can house the logic ...

The Three.js IEWebGL Plugin

After developing a code that successfully rotates a cube with trackball using the three.js library and webgl, I encountered compatibility issues when trying to run it on Internet Explorer 10. Despite downloading IeWebgl to assist in making it run on IE10 ...

Is there a way to modify the color scheme of my webpage while utilizing Bootstrap?

As I delve into programming with Bootstrap, I encountered an issue while attempting to change the background color of my body. Even though I used the following CSS code: body { background-color: #eba; width: 100%; height: 100%; } The color change ...

Angular 5 mobile row aligns vertically, not inline with Bootstrap

Is there a way to make the row inline when the width is less than 579px? I want it to look the same on both mobile and desktop. "styles": [ "../node_modules/font-awesome/scss/font-awesome.scss", "../node_modules/angular-bootstrap-md/scss/bootstra ...

Seeking an efficient localStorage method for easy table modification (HTML page provided)

Currently, I am in the process of developing a custom 'tool' that consists of a main page with a menu and several subpages containing tables. This tool is intended for composing responses using prewritten components with my fellow colleagues at w ...

CSS failed to load on HTML page

Having trouble loading a CSS file. I've attempted: <link href="./css/style.css" rel="stylesheet" type="text/css"> And: <link href="css/style.css" rel="stylesheet" type="text/css"> And even tried without the "css" directory in the name ...

Updating a section of a webpage using jQuery Mobile

I'm currently facing an issue with modifying a specific section of my webpage. Although this problem has been discussed before, I haven't found a satisfactory solution yet. The element in red on the page needs to change dynamically based on the ...

Tips for maintaining a single-line div while adding ellipses:

What is the CSS way to ensure that a div or class contains only one line of text, with ellipses added if it exceeds that limit? I am aware that setting a specific height and using overflow:hidden can achieve this, but it doesn't quite work for my need ...

if the total is less than 12, the column will expand to its full width

Within the code snippet provided, there are three columns in a row. The first column occupies half of the row's width. However, there may be scenarios where the red and blue columns are either added to or removed from the DOM dynamically. Is there a ...

CSS for positioning tabs by sliding

Can someone assist me with properly positioning my Sliding TAB? It appears fine in my browser, but on other computers with varying resolutions, it overlaps with another tab. If you'd like to view the site, click this LINK Below is the code I am usin ...

What is the correct way to retrieve a JSON object instead of getting [Object object]?

Creating a basic web scraper integrated with mongoDB. Even though the API returns the JSON object in the correct format, when trying to append it to a bootstrap card on the page, I'm getting [Object object]. Below is my JavaScript code running on th ...

What is the process for connecting the Facebook icon in Bootstrap 4 to my personal Facebook account, or the Google Mail icon to my Google Mail account?

When it comes to designing a webpage, I am looking to connect my Facebook account with an icon of Facebook, my Google mail with Google mail account, and my LinkedIn account with the LinkedIn icon. What is the code line needed to accomplish this task? ...

What is the best way to achieve maximum clarity in a div element while adjusting opacity?

Is there a way to have a div with an opacity of 40%, but make the text inside the div show with an opacity of 100%? #box { Background-color:#000; Opacity:40%; } ...

I have an HTML page containing a form that I would like to save to a file, in order to utilize the file's content within my application

I have an HTML page and an Android app, both are separate but hosted on the same server. I want to retrieve input field values from a form and save them in a text file. Then, I plan to use these values from the text file for further processing. For examp ...