Personalized FileInput within a card - Bootstrap 5

I am attempting to incorporate a custom file selection feature within a Bootstrap card:

Here is my attempt:

<style>
label {
   cursor: pointer;
}
.custom-input-image {
   opacity: 0;
   position: absolute;
   z-index: -1;
}
</style>


<div class="row mb-2">
  <div class="col-md-4 text-center">
    <input type="file" id="id_img_1" name="id_img_1" class="custom-input-image">
    <label for="id_img_1" class="hover-shadow-lg hover-translate-y-n3">
      <div class="card">
        <div class="card-body text-center">
          <!-- Image content-->
          <div>
            <div>
              <h4 class="mb-1"><i class="camera-icon"></i></h4>
              <small>Select file...</small>
            </div>
          </div>
        </div>
      </div>
    </label>
  </div>
  [...more cards..]
</div>

With the current setup, I achieve the following effect: https://i.sstatic.net/wnd2N.png

However, I am aiming for this look: https://i.sstatic.net/kegBY.png

When adding a label to the card, it causes the card to shrink. How can I make sure the card retains its full length despite the file selection addition?

Answer №1

If you're looking to enhance your design, consider using different icons instead of font-awesome icons as placeholders. Here's an example of how you can achieve that:

label {
  cursor: pointer;
  display: block;
  font-size: 0.875rem;
  margin-top: 10px;
}

.custom-input-image {
  opacity: 0;
  position: absolute;
  z-index: -1;
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3f5d50504b4c4b4b5e5f7f0a110f110d">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet">

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" />

  <div class="col-md-12 col-sm-12">
    <div class="row g-2 mt-3">
      <div class="col-md-4 col-sm-4 text-center">
        <input type="file" name="" id="" class="custom-input-image">
        <div class="card p-4 border border-3">
          <i class="fas fa-camera fa-2x"></i>
          <label for="">Select file</label>
        </div>
      </div>
      <div class="col-md-4 col-sm-4 text-center">
        <input type="file" name="" id="" class="custom-input-image">
        <div class="card p-4 border border-3">
          <i class="fas fa-camera fa-2x"></i>
          <label for="">Select file</label>
        </div>
      </div>
      <div class="col-md-4 col-sm-4 text-center">
        <input type="file" name="" id="" class="custom-input-image">
        <div class="card p-4 border border-3">
          <i class="fas fa-camera fa-2x"></i>
          <label for="">Select file</label>
        </div>
      </div>
    </div>
  </div>

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

The material UI Paper component appears to be extending beyond the boundaries of the background image

I have configured the Grid component to occupy 6 on small/medium screens for a side-by-side layout and 12 on xs screens for each item. While everything looks fine in the computer view, I am facing an issue with the mobile view where the paper component is ...

Modify image on webpage using PHP every second

My website has a feature that dynamically changes the picture source and displays a new image using a combination of PHP and JQuery. Here is the PHP5 script I am using: <?php header("Content-Type: image/jpeg"); $page = $_SERVER['PHP_SEL ...

What could be the reason for the malfunctioning dropdown menu in my navigation bar upon clicking it?

After spending hours practicing creating a navbar using Bootstrap 3.3.7, I've hit a roadblock - the dropdown is not working when clicked on. It's frustrating because I have double-checked all my scripts and ensured that I have the latest version ...

The custom switch input with a blue outline is reluctant to vanish

Hey there! I'm currently using Bootstrap and I'm facing an issue with removing the blue outline around a custom switch button when clicked. I've tried to remove it using CSS but it doesn't seem to work, especially in Chrome. Here's ...

Hover effect not displaying upon mouse exit

I am working on a feature where a series of images change when hovered over, with a div animating as an overlay on the image. Here is the code snippet: // hiding overlays initially $(".mini-shop .item .image a div").hide(); // toggling overlay and second ...

Ways to remove the initial row of inline-block divs

My webpage is filled with inline-block divs that are contained within a larger div like so: <div class="container"> <div class="text">Text 1</div> <div class="text">Text 2 ... rest of the nu ...

What are the implications of adding custom attributes to HTML elements?

Similar Questions: Custom attributes - Good or Bad? Non-Standard Attributes on HTML Tags. What are Your Thoughts? While working on a current learning project, I encountered the need to add an attribute that would store a numerical value. Initially ...

What is the best way to use JavaScript to fill in missing images with alternative HTML content?

As a provider of a service that helps users find the location of pictures, I face a challenge due to the fact that the pictures are stored on another internal site. Some users may not have access to this site as my service offers additional information. Th ...

The Bootstrap 4 grid appears to be malfunctioning as the columns are not displaying next to each other as expected

I've implemented the code below in an attempt to achieve the desired layout shown in the image, but instead, I'm getting a different outcome. Can someone help me figure out what I might be doing wrong with the Boostrap 4 grid system? I'm co ...

The function "getElementsByClassName" in Javascript is malfunctioning

I have redesigned my website by implementing an interactive feature where users can click on a tree image to remove it and replace it with a number using JavaScript. Initially, I targeted the specific tree with the following code: document.getElementById( ...

Inserting data into a JavaScript database

When attempting to add a new row to a datatable and submit it to a JSP for database insertion, an error is encountered. The error message reads: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the r ...

Implementing background color changes based on a database value (sex) using JavaScript

Visualization: [IMG]+[HIDDEN INPUT]-—-[TEXT]-—-[ICON] [IMG]+[HIDDEN INPUT]-—-[TEXT]-—-[ICON] [IMG]+[HIDDEN INPUT]-—-[TEXT]-—-[ICON] (For each individual) I am looking to match the background color of the icon on the right with the IMG on the ...

Reloading a webpage does not clear HTML tables containing jQuery interactions in Firefox

Apologies if this question has already been asked. I incorporated hide/unhide features using jQuery into a simple HTML table. The table functioned correctly in Chrome 24.0.1312.52 m and IE8+. Yet, upon refreshing the page in Firefox 15.0.1, the pr ...

Overlap bug with Flash content

In both Google Chrome (16.0.912.75 m) and Safari (5.1.1), I am encountering the well-known flash / html overlay issue. Despite setting the wmode attribute to transparent as suggested here and here, along with trying opaque, the problem persists. Following ...

Adjust the size of a division based on the width of the screen using JavaScript

Is there a way to create a JavaScript function that dynamically adjusts the size of a div, image, or padding based on the screen width without using CSS? I am specifically interested in adjusting the padding of a div element. Here is a sample code snippet ...

Looking to create a form that automatically updates the second dropdown list when I make a selection in the main dropdown menu

<div> <label for="form-field-select-3">State : </label> <br /> <select class="chosen-select form-control" id="State" n ...

Steps for embedding the code into your website

I'm facing an issue with integrating a .jsx file into my website. I tried testing it on a single-page demo site, but nothing is showing up. Can someone guide me through the steps to successfully integrate it onto my site? I've also attached the . ...

Troubleshooting the issue with reactdom.render() functionality in CodeSandbox

Having issues with ReactDom in CodeSandbox for React. The HTML file includes: <body> <div id="root"></div> </body> <script src="scr/index.js"> The JavaScript file (named index) includes: ReactDOM.rende ...

Press the Concealed Button Enclosed in a div Using Selenium with Python

Currently, I am in the process of automating the login on the Workday portal by utilizing Chrome WebDriver in Selenium. My main challenge lies in figuring out how to click on a hidden sign-in button with the following properties: <div class="css-1s ...

Steps to vertically shift an image downwards within a navigation bar using HTML and CSS

Currently, there is a fully functional navigation menu that can be toggled within a webpage. An image is also included in the navigation menu and positioned below the text. I would like to move the image to the very bottom of the navigation menu to remove ...