Adjusting the width of the Bootstrap input group-prepend/addon

I am encountering difficulties with ensuring that all prepend add-ons have the same width. The issue arises when using Font Awesome icons, as each prepend is sized according to its specific icon. I came across a similar thread from approximately one year ago addressing the exact problem, yet lacking a solution.

Bootstrap4 make all input-group-addons same width

Below is a visual representation of the problem:

https://i.sstatic.net/8uxut.png

Despite attempting various CSS adjustments, including the one suggested in the aforementioned discussion, I have been unsuccessful in resolving the issue.

Here is the pertinent HTML code snippet:

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row body-main-bg">
  <div class="col-sm-4 my-3">
    <div class="input-group">
      <div class="input-group-prepend">
        <span class="input-group-text">
          <span class="fa fa-user"></span>
        </span>
      </div>
      <input type="text" class="form-control" placeholder="Name">
    </div>
  </div>
</div>
<div class="row body-main-bg">
  <div class="col-sm-4 mb-3">
    <div class="input-group">
      <div class="input-group-prepend">
        <span class="input-group-text">
          <span class="fa fa-envelope"></span>
        </span>
      </div>
      <input type="text" class="form-control" placeholder="Email">
    </div>
  </div>
</div>
<div class="row body-main-bg">
  <div class="col-sm-4 mb-3">
    <div class="input-group">
      <div class="input-group-prepend">
        <span class="input-group-text">
          <span class="fa fa-ellipsis-v"></span>
        </span>
      </div>
      <input type="text" class="form-control" placeholder="Subject">
    </div>
  </div>
</div>
<div class="row body-main-bg">
  <div class="col-sm-4 mb-3">
    <div class="input-group">
      <div class="input-group-prepend">
        <span class="input-group-text">
          <span class="fa fa-pencil"></span>
        </span>
      </div>
      <textarea class="form-control" id="exampleFormControlTextarea1" rows="3" placeholder="Message"></textarea>
    </div>
  </div>
</div>

Answer №1

After experimenting with your code snippet and making some minor CSS adjustments, I was able to get it to work perfectly for me. I included the following CSS tweaks: Please make use of this CSS to resolve the width problem with prepended/addon elements.

.input-group-text {
    width: 40px;
}
.input-group-text span {
    margin: 0 auto;
}

You can also find the snippet at the link below, bootstrap-input-group-prepend-addon-width-issue

Answer №2

In my opinion, the most straightforward solution for this issue is utilizing the power of css grid.

.container
{
display:grid;
grid-template-rows: repeat(3,1fr) 2fr;
grid-template-columns: 15% 85%;
grid-row-gap:1rem
}

After that, you can easily assign icons to the first column and input fields to the second column.

I trust that this resolves your query.

Answer №3

<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" rel="stylesheet" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<div class="modal-body" id="m_cr_body">
  <div class="input-group input-group-sm mb-3">
    <div class="input-group-prepend w-25">
      <span class="input-group-text w-100" id="inputGroup-sizing-sm"><i class="fas fa-camera  fa-fw"></i> Photographer</span>
    </div>
    <input type="text" class="form-control" aria-label="Small" aria-describedby="inputGroup-sizing-sm">
  </div>
  <div class="input-group input-group-sm mb-3">
    <div class="input-group-prepend w-25">
      <span class="input-group-text w-100" id="inputGroup-sizing-sm"><i class="fas fa-paint-brush  fa-fw"></i> Edit</span>
    </div>
    <input type="text" class="form-control" aria-label="Small" aria-describedby="inputGroup-sizing-sm">
  </div>
  <div class="input-group input-group-sm mb-3">
    <div class="input-group-prepend w-25">
      <span class="input-group-text w-100" id="inputGroup-sizing-sm"><i class="fas fa-ruler-vertical  fa-fw"></i> Rule</span>
    </div>
    <input type="text" class="form-control" aria-label="Small" aria-describedby="inputGroup-sizing-sm">
  </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

Creating a customizable CSS selector in an Angular.js application

I'm currently developing a project in Angular.js involving a plane view where various objects are located. Every time a user drags an item from the left menu bar to the center of the screen, a new object is created. The unique CSS class for each item ...

Guide to designing a bar graph using HTML5 for a web app optimized for iPad

I am in the process of converting my iOS native app for iPad to a web app using HTML5. However, I am encountering an issue with creating a bar graph for the HTML5 app. Is there any documentation or built-in API available for this specific task? On iOS, we ...

Is there a way to ensure that spans are inline with a div?

My structure is pretty straightforward: <div></div><span></span><span></span> However, I'm looking to have them all appear on a single line. Currently, they are rendering like this: <div /> <span />&l ...

Volume slider missing on Handel?

I'm having an issue with my volume slider in jQuery - the handle is not showing up despite it working. Any suggestions on how to make the handle visible? The jQuery I have imported: <script src="jquery-3.4.1.min.js"></script> <script ...

Unable to view HTML without an internet connection

I have encountered an issue where my files work fine when uploaded to an online server, but do not work when accessed locally offline. An error message about a cross-origin issue appears. How can I solve this problem? Error message: Security Error: Conte ...

Angular CLI is not displaying CSS

I am currently using angular cli version 1.4.3, node version 6.11.3, and npm version 5.4.2. My goal is to retrieve records using angular2 and display them on localhost. I expected the output to look like this: https://i.sstatic.net/S8TVI.jpg however, the ...

I'm looking for a library or plugin that can be used to develop a customizable sidebar window with docking, resizing, and pinning capabilities similar to the ones found

In Visual Studio, the solution explorer and toolbox windows can be hidden at the side unless pinned. They are also resizable. Is there a way to achieve this same behavior using CSS? Has anyone created a jQuery plugin or similar tool for this? ...

Adjust the position of a textarea on an image using a slider

Currently, I am exploring how to creatively position a textarea on an image. The idea is to overlay the text on the image within the textarea and then use a slider to adjust the vertical position of the text as a percentage of the image height. For instanc ...

Error occurs when checkboxes are left unchecked in CherryPy web form

Currently, I am in the process of creating a straightforward web form using CherryPy in Python 3.5 to interact with an sqlite3 database, which requires input of various data types. I encountered an issue where leaving checkboxes unchecked resulted in an er ...

How can Bootstrap be utilized for Image Overlay?

I'm currently using bootstrap and have a 3x3 grid of 200x200 images. I've searched everywhere for a solution to add an overlay, but haven't had any luck so far. I'm still new to coding and trying to figure things out. I saw on Serenbe. ...

What is the process for submitting a form on consecutive URLs?

I have a form that requires input for settings and includes two buttons: one to save the form and another to both save and execute the settings. <form method="post" action="/settings/{{id}}/save"> <!-- input fields --> ...

"Using Selenium in Python to navigate Google's search results and view the

Hello, I am new to using selenium and I have a specific task in mind. I would like to scrape the address search results from Google that are displayed on the sidebar column. I have successfully managed to use selenium to conduct searches on Google and land ...

Utilize JavaScript to send an email containing a link and content

In the html form, there are input fields for adding a new user to the database. Once a user is added, an email is sent to them using the sendmail() function in the adduser.js file. The email is sent successfully according to my standards. However, I want t ...

Transferring ipywidgets to a web platform

I've developed a Python program in Jupyter Notebook that leverages the interact function from the ipywidgets module. interact(my_func, filter_by=filter_by_list, format_type=format_dict.keys()) I am looking for a way to share this interactive widget ...

Tips for displaying multiple values from a MySQL count as a single column in HTML and PHP

$query="SELECT data_home.name_home, GROUP_CONCAT(flower.flower) AS flowers FROM data_home INNER JOIN (flower INNER JOIN home_flower ON flower.id_flower=home_flower.id_flower) ON data_home.id_home = home_flower.id_home GR ...

Utilizing angularjs ng-repeat directive to present JSON data in an HTML table

I've been struggling to showcase the JSON data in my HTML table using AngularJS ng-repeat directive. Here's the code snippet: <thead> <tr> <th ng-repeat="(header, value) in gridheader">{{value}}</th> </tr> </ ...

I'm having trouble figuring out how to add a link to a page using TypeScript. I attempted one approach, but it doesn't seem to be working

`<CommandItem><a href="@/src/app/page.tsx">My stats</a></CommandItem>` I attempted this code but it did not function as expected. I sought assistance from various methods on stackoverflow, however none of them were succes ...

The element's position remains unchanged after the .click re-event in the function

Welcome to my first attempt at using jQuery! Please bear with me as I navigate through this learning process. Here's the challenge: I have a series of elements in my HTML. <div class="garden"> <div class="point left">&#9668;</d ...

Webpack version 4.6.0 is currently loading a CSS file and it's suggesting the need for a suitable loader to manage this specific file

I have been encountering an issue with webpack 4.6.0 during compilation: Uncaught Error: Module parse failed: Unexpected token (1:4) You may need an appropriate loader to handle this file type. | div { | background-color: yellow; | color: red; He ...

Creating a custom HTML pattern input for restricting input to only specific numbers

I need to set a specific requirement for the zip code section of my form. Only 5 numbers are allowed, and it must start with either 46,52,53,54,60,61,62 as specified in an html pattern. ...