Collection of components displayed in a row - Bootstrap 4

In order to meet the requirement, the label must be positioned above the input element, and the group consisting of each label and input element should be displayed inline with one another.

I have managed to achieve this using the following code snippet, especially when the label text is long. However, when the text of the label is short, the input element aligns differently.

I suspect that I may be implementing this incorrectly. Could someone please suggest a better way to handle this using bootstrap?

Thank you in advance.

Code -


    <form class="form" id="taxCalcDetail">
      <div class="form-inline">
        <div class="form-group col-lg-3 pb-3">
          <label class="small pb-1">A1</label>
          <input type="text" name="t1" class="form-control" id="t1">
        </div>
        <div class="form-group col-lg-3 pb-3">
          <label class="small pb-1">A2</label>
          <input type="text" name="t2" class="form-control" id="t2">
        </div>
        <div class="form-group col-lg-3 pb-3">
          <label class="small pb-1">A3</label>
          <input type="text" name="t3" class="form-control" id="t3">
        </div>
      </div>
    </form>
  

Answer №1

Consider using the d-flex and flex-column classes. When tested on various Bootstrap 4 playgrounds, it functioned as intended. For further information, you can refer to this link.

<form class="form" id="taxCalcDetail">
    <div class="form-inline">
        <div class="form-group col-md-4">
            <div class="d-flex flex-column">
                <label for="name" class="control-label">A1</label>
                <input type="text" class="form-control" id="lineHeight">
            </div>
        </div>
    <div class="form-group col-md-4">
        <div class="d-flex flex-column">
            <label for="name" class="control-label">A2</label>
            <input type="text" class="form-control" id="lineHeight">
        </div>
    </div>
    <div class="form-group col-md-4">
        <div class="d-flex flex-column">
            <label for="name" class="control-label">A3</label>
            <input type="text" class="form-control" id="lineHeight">
        </div>
    </div>
    </div>
    </form>

Answer №2

One useful class in bootstrap 4 is d-inline-block

  <form class="form" id="taxCalcDetail">
  <div class="form-inline">
     <div class="form-group col-lg-3 pb-3">
        <label class="small pb-1 d-inline-block">A1</label>
        <input type="text" name="t1" class="form-control" id="t1">
     </div>
     <div class="form-group col-lg-3 pb-3">
        <label class="small pb-1 d-inline-block">A2</label>
        <input type="text" name="t2" class="form-control" id="t2">  
     </div>
     <div class="form-group col-lg-3 pb-3">
        <label class="small pb-1 d-inline-block">A3</label>
        <input type="text" name="t3" class="form-control" id="t3">  
     </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

Mastering the Art of Defining JavaScript Classes in React-Native

In my React Native project, I am faced with a situation where I need to create a new class: class customClass { email: string; name: string; constructor() { setUser(fbid: string, token: string): boolean { To keep things organized, I decide ...

The error message "Property 'push' of undefined in AngularJS" occurs when the push method is being called

I'm currently working on developing a basic phonebook web application to enhance my knowledge of Angular, but I've encountered an issue with this error message - "Cannot read property 'push' of undefined". Can anyone help me identify th ...

Exploring CryptoJS in a Vue.js project

https://github.com/brix/crypto-js I successfully installed CryptoJS using npm i crypto-js. However, I am facing difficulty in integrating it into my project. When I attempt to use the following code: // Decrypt var bytes = CryptoJS.AES.decrypt(cipher ...

Is it possible to utilize global variables within CSS properties?

I have a scenario where I need to dynamically change values in an animation. The line of code that needs modification is: clip-path: polygon(var(clip1) 0, 100% 1%, 100% 100%, 50% 100%); let root = document.documentElement; root.style.setProperty('c ...

Incorporating React.js with a server API that doesn't use JavaScript

My upcoming project involves enhancing my current application frontend by implementing React.js. The existing frontend currently utilizes standard REST calls to communicate with a server built using Microsoft technologies, and there are no plans of changin ...

Ways to change the label of an input field with JQuery

Here is an example of HTML code: <div class="task-manager"> <label>Manager: <input type="text" value="" /></label> </div> I am looking to change the text of the label "Manager" dynamically. I attempted to use the JQUERY ...

Is it necessary to use JS/JQ to trigger PHP form data?

Can PHP files/functions be executed without reloading the page? It can be quite disruptive when developing a chat app and every time you send a message, the entire page refreshes. I attempted to use AJAX but it didn't work. Is it not possible to send ...

Creating a CSS container with a uniquely shaped rounded triangle/arrow design

I would like to create a container background with a rounded arrow design. The arrow should always stretch to the full width of the container and be able to adjust its height dynamically (I can use JavaScript if needed to adjust the height). Here's a ...

Changing the 'null' string to null in JavaScript

Within an array of objects, some keys have a value of "null" as a string that I want to convert to null. Here is the code I tried: let obj = [{ "fundcode": "DE", "fundname": "Defens", ...

Enhancing React URLs

Our company deals with URLs in this format: http://helloworld.com/product?filter[category][0]=persian We aim to transform the URL into a cleaner version: http://helloworld.com/product-persian When additional filters are added to the current UR ...

Significant delay in fetching model data for controller via XHR

My controller is designed to make an ajax call to retrieve its model, which is a 4.5k json containing a 2d array. This data is then used to create a combo displaying a series of labels in the html below: <select data-ng-controller="CGSimpleXHRComboCont ...

Is it possible to remove a record using jQuery AJAX from a table that has rows dynamically added using AJAX?

I am encountering an issue where I am unable to access or select the delete buttons in my table rows, which are populated within the table body using ajax on document load. It seems that this problem is arising due to the asynchronous nature of ajax. I a ...

Issue encountered while compiling ReactJs: Unexpected token error found in App.js

I executed the commands below. npx create-react-app github-first-app npm install --save react-tabs npm i styled-components npm install git-state --save using the following code files App.js import React from "react"; import Layout from " ...

Refresh ng-repeat array after implementing filter in controller

I am currently facing an issue with updating my table view when changing a variable that filters an array. The filter is applied in the controller based on the values of a specific variable called columnFilter. However, the filter does not reapply to updat ...

Is there a way to automatically calculate the sum of two boxes and display the result in a separate

I am working with two boxes: one is called AuthorizedAmount and the other is called LessLaborToDate: <div class="col-md-6"> <div class="form-group"> <label>Authorized Amount</label> <div class="input-group"> & ...

Ways to have the right sidebar seamlessly blend in with the page content by hovering over it rather than occupying a separate area

While working on the design of my website, I encountered a challenge with the sidebar. I aim to have a sidebar that hovers from the right side to the left, displaying the full content when the cursor is placed over it, much like the one featured on . Altho ...

Server-side rendering or updating of React elements

One issue I am facing in my React app is that while all components can update themselves through the browser, a specific module called jenkins-api only functions when called server side. To retrieve the data and pass it into my template, I have utilized th ...

Utilizing the GET method within a form

I'm currently working on testing a form to ensure that my input values are being submitted correctly. At this point, I haven't set up any server script yet. However, I was hoping that upon clicking submit, I would be able to see my values appende ...

Contrasting outcomes when tackling a problem in node.js versus python

After tackling a challenging leetCode problem, I successfully came up with the following solution: Given d dice, each with f faces numbered from 1 to f, determine the number of possible ways (modulo 10^9 + 7) to roll the dice so the sum of the face up nu ...

The value is currently unset in the TypeScript language

The variable `this.engenes_comparte` is showing up as undefined inside the subscribe function, but it works fine outside of it. baja(){ this._restService.getEngines(this._globalService.currentFisherMan.nid).subscribe((data : any[]) => { le ...