The select element is displaying with a different width compared to its sibling, causing the Bootstrap spacing to over

Working on styling an input form using Bootstrap-4. I have an input field and a select field, both having the class "col" with different spacing classes. However, the select field appears slightly smaller.

When I assign the class "col-6" to both fields, they end up being the same length but lack the necessary spacing required for my design. Adding spacing causes one of the items to move to the next line.

Snippet available at: https://jsfiddle.net/p81z7Lfg/1/

<div class="container">
  <div class="row">
    <input type="text" class="col mr-1" value="1">
    <input type="text" class="col ml-1" value="2">
  </div>

  <div class="row">
    <input type="text" class="col mr-1" value="3">
    <select class="col ml-1">
      <option selected>4</option>
    </select>
  </div>

  <div class="row"></div>

  <div class="row">
    <input type="text" class="col mr-1" value="1">
    <input type="text" class="col ml-1" value="2">
  </div>

  <div class="row">
    <input type="text" class="col-6 mr-1" value="3">
    <select class="col-6 ml-1">
      <option selected>4</option>
    </select>
  </div>
</div>

An elegant Bootstrap solution would be ideal to maintain project consistency in styling and coding without resorting to custom CSS within Bootstrap components.

Appreciate your assistance.

Answer №1

The default structure for a form in Bootstrap version 4 is as follows:

div.row 
  div.col
    input.form-control
  div.col
    input.form-control
div.row
  div.col
    select.form-control
      option
      option
      ...
  div.col
    any-other-form-element.form-control

You have the flexibility to change the .col classes to other .col-*-* classes based on your desired layout for different screen sizes.

Additionally, you can replace .row with .form-row, as mentioned in the official documentation:

You may also substitute .row with .form-row, which modifies the standard grid row by adjusting the default column gutters for more condensed and compact designs.

View an example here.

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

Are HTML5 Track Element Cue Events Working Properly?

My goal is to dynamically assign functions to HTML5's cue.onenter events. This feature is relatively new and currently only supported in Chrome with specific flags enabled (Refer to the example on HTML5 Rocks here). However, I seem to be facing some ...

The spacing between elements in Flexbox is too excessive, creating an overly wide gap

How can I maintain a fixed 40 pixel gap between columns in flexbox without it increasing as the screen width widens? (I apologize for the brevity of this description, but there are no additional details to provide at this time) .browser-box { max-wid ...

Breaking the page with HTML and CSS

* { box-sizing: border-box; } .row { display: flex; } /* Creating two equal columns that sit side by side */ .column { flex: 50%; padding: 10px; } div.row { page-break-after: always; } <body> <div<div class="row"> ...

Looking for a JavaScript code to create a text link that says "submit"?

Here is the code I have, where I want to utilize a hyperlink to submit my form: <form name="form_signup" id="form_signup" method="post" action="/" enctype="multipart/form-data"> ... <input type="submit" value="Go to Step 2" name="completed" /> ...

Display the contents of a JSON array in an HTML format

I have designed an exercise that requires me to display the cities corresponding to each department based on a JSON file. Currently, I am able to display the departments in their respective selections, but I am struggling to only show the cities that corre ...

What is the best way to widen each tab so they fill up the entire width of the content block?

As a newcomer to both programming and this website, I've been exploring various codes for creating vertical and horizontal tabs. I have a specific query about this particular example found at https://jsfiddle.net/eu81273/812ehkyf/: My goal is to adju ...

What is preventing me from concealing my input field when its type is set to "file"?

I've been attempting to conceal my input field of a file type, but even with the hidden attribute, it refuses to hide. https://i.sstatic.net/jyMrn.png https://i.sstatic.net/P59wV.png Interestingly, once I remove type="file", the code succe ...

Having trouble transferring a variable from getJSON data to PHP

I am encountering an issue with my jQuery getJSON method when trying to pass data to PHP. Strangely, I am unable to pass a variable. In another part of my code, passing the variable works fine. Additionally, hardcoding the string or using a valid variable ...

Issue with resizing a Bootstrap pill containing truncated text

After struggling with this issue for some time, I attempted to use javascript to solve it but have been unsuccessful. The challenge involves a tag list in a table that displays a link when hovered over. Following advice from another member on SO, I managed ...

Maintaining the active status of section 1 after the page is refreshed using Javascript and CSS

I have a total of 3 buttons and 3 hidden sections available, which can be seen in the image below: click here for image description Whenever one of the buttons is clicked, the respective section transitions from being hidden to becoming visible: click he ...

Styling just a single div when the state changes

I have a scenario where I am rendering 4 divs based on data fetched from my backend. Each div is colored according to a state change. While I have successfully implemented this, the issue is that all 4 divs can be colored in this way simultaneously. I want ...

Conceal the heading 4 element when a specific text is searched

I have a search script that filters the text, but I want to hide the h4 element at the top of each ol. How can I achieve this? The issue I'm facing is that while the text gets filtered correctly, the h4 element (which should be hidden) remains visibl ...

Tips for displaying specific information using Javascript depending on the input value of an HTML form

I am working on an HTML form that includes a dropdown list with four different names to choose from. window.onload = function(){ document.getElementById("submit").onclick = displaySelectedStudent; } function displaySelectedStu ...

Access a document by selecting a particular page from a designated anchor tag

Seeking assistance from the community on opening a particular page within a file using an anchor tag (<a href=""></a>). The issue arises when trying to pass a parameter through the xls file, as it prevents locating the specified page. Any gui ...

Break down the organization of CSS

While exploring a website, I came across this CSS code that sets the font family to "Open Sans," Helvetica, Arial, and sans-serif. However, I am having trouble understanding this structure. Any assistance would be greatly appreciated. Thank you in advanc ...

What is the best way to monitor and record the height of a div element in a React application?

Exploring the Height of a Div I am interested in monitoring the height of a div element so that I can dynamically adjust distances based on varying screen widths. The animation should respond to changes in screen width, such as when text stacks and the he ...

What is the best way to stop div animations when clicking with jQuery?

Upon loading the page, a div animates automatically. There is also a button present. When the button is clicked, I would like to create a new div and animate it the same way as the first one. However, when this happens, the position of the first div also ...

Checkbox: Customize the appearance of the root element

I am trying to modify the root styles of a Checkbox component, but it is not working as expected. Here is my code: <CheckboxItem onChange={()} checked={isChecked} label="Show Checkb ...

Creating Transparent Rounded Backgrounds in Google Chrome Packaged Apps: Achieving the same look as Google Hangout app

Looking at the screenshot below, it is evident that the Hangout app has a fully transparent design with background shadow effect applied to it. I have tried various methods in vain, such as applying CSS styling to the "html" and "body" tags of the page, a ...

When importing data from a jQuery AJAX load, the system inadvertently generates duplicate div tags

Currently, I am utilizing a script that fetches data from another page and imports it into the current page by using the .load() ajax function. Here is the important line of code: $('#content').load(toLoad,'',showNewContent()) The issu ...