Master the art of aligning columns to the right with Bootstrap 5

Struggling to align the two fields, "Currency I Want" and "Amount," from left-bottom to right-top in Bootstrap 5. Hours have been spent trying to figure it out with no success. Can anyone provide assistance?

[1]: https://i.sstatic.net/0Yjdu.jpg [1]

Below is the code snippet:

return (
 <div className="card card-body p-3 mb-2 bg-light text-dark">
  <h1>Currency Converter</h1>
    <form>
      <div class="form-row">
        <div class="form-group col-md-4">
          <label>Currency I have:</label>
          <select className="form-select" type="text" >
            <option value="1" selected >USD</option>
            <option value="2">EUR</option>
            <option value="3">GBP</option>
          </select>
        </div>
        <div className="form-group col-md-4">
          <label>Amount:</label>
          <input type="number" className="form-control"/>
        </div>
      </div>
      <div className="form-row">
        <div className="form-group col-md-4">
          <label>Currency I Want:</label>
          <select className="form-select" type="text" >
            <option value="1" selected >USD</option>
            <option value="2">EUR</option>
            <option value="3">GBP</option>
          </select>
        </div>
        <div className="form-group col-md-4">
          <label>Amount:</label>
          <input type="number" className="form-control"/>
        </div>
      </div>
      <button type="submit" className="btn btn-secondary mb-2">Convert</button>
    </form>
  </div>
);

Answer №1

Start by creating a new div that spans across both columns and apply the d-flex class to it.

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.2/css/bootstrap.min.css">
<div class="card card-body p-3 mb-2 bg-light text-dark">
  <h1>Currency Converter</h1>
    <form>
      <div class="d-flex">
      <div class="form-row col-md-6 col-sm-6">
        <div class="form-group col-md-8">
          <label>Currency I have:</label>
          <select class="form-select" type="text" >
            <option value="1" selected >USD</option>
            <option value="2">EUR</option>
            <option value="3">GBP</option>
          </select>
        </div>
        <div class="form-group col-md-8">
          <label>Amount:</label>
          <input type="number" class="form-control"/>
        </div>
      </div>
      <div class="form-row col-md-6 col-sm-6">
        <div class="form-group col-md-8">
          <label>Currency I Want:</label>
          <select class="form-select" type="text" >
            <option value="1" selected >USD</option>
            <option value="2">EUR</option>
            <option value="3">GBP</option>
          </select>
        </div>
        <div class="form-group col-md-8">
          <label>Amount:</label>
          <input type="number" class="form-control"/>
        </div>
      </div>
      </div>
      <br/>
      <button type="submit" class="btn btn-secondary mb-2">Convert</button>
    </form>
  </div>

Answer №2

Implementing float-end in form row

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d6b4b9b9a2a5a2a4b7a696e3f8e7f8e7">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">

<div className="card card-body p-3 mb-2 bg-light text-dark float-right">
  <h1>Currency Converter</h1>
  <br>

    <form>
        <div class="form-row float-end">
           
           <div class="form-group col-md-4">
              <label>Currency I have:</label>
               <select className="form-select" type="text" >
                  <option value="1" selected >USD</option>
                  <option value="2">EUR</option>
                  <option value="3">GBP</option>
                </select>
            </div>

            <div className="form-group col-md-4 float-end">
            <label>Amount:</label>
            <input type="number" className="form-control"/>
          </div><br>
        </div>
         
        <div className="form-row">
          <div className="form-group col-md-4">
            <label>Currency I Want:</label>
            <select className="form-select" type="text" >
              <option value="1" selected >USD</option>
              <option value="2">EUR</option>
              <option value="3">GBP</option>
            </select>
          </div><br/>
          <div className="form-group col-md-4 ">
            <label>Amount:</label>
            <input type="number" className="form-control"/>
          </div><br/>
        </div>
        <button type="submit" className="btn btn-secondary mb-2">Convert</button>
    </form>
  </div>

Explore Further Information

Answer №3

How do I Align the 2 Rows to the Right End with a Button in the Middle?

Check out my updated image after implementing the solution

Here is my revised source code snippet:

  return (
    <div class="card card-body p-3 mb-2 bg-light text-dark">
      <h1>Currency Converter</h1>
        <form>
          <div class="d-flex justify-content-between align-items-center">
          <div class="form-row col-md-6 col-sm-6">
            <div class="form-group col-md-8">
              <label>My Currency:</label>
              <select class="form-select" type="text" >
                <option value="1" selected >USD</option>
                <option value="2">EUR</option>
                <option value="3">GBP</option>
              </select>
            </div>
            <div class="form-group col-md-8">
              <label>Amount:</label>
              <input type="number" class="form-control"/>
            </div>
          </div>
          <div class="form-row col-md-6 col-sm-6 float-right">
            <div class="form-group col-md-8">
              <label>Desired Currency:</label>
              <select class="form-select" type="text" >
                <option value="1" selected >USD</option>
                <option value="2">EUR</option>
                <option value="3">GBP</option>
              </select>
            </div>
            <div class="form-group col-md-8">
              <label>Amount:</label>
              <input type="number" class="form-control"/>
            </div>
          </div>
          </div>
          <br/>
          <button type="submit" class="btn btn-secondary mx-auto mb-2">Convert</button>
        </form>
      </div>
    );
  }

Answer №4

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.2/css/bootstrap.min.css">
<div class="card card-body p-3 mb-2 bg-light text-dark">
  <h1>Currency Converter</h1>
    <form>
      <div class="d-flex">
      <div class="form-row col-md-6 col-sm-6">
        <div class="form-group col-md-8">
          <label>Currency I have:</label>
          <select class="form-select" type="text" >
            <option value="1" selected >USD</option>
            <option value="2">EUR</option>
            <option value="3">GBP</option>
          </select>
        </div>
        <div class="form-group col-md-8">
          <label>Amount:</label>
          <input type="number" class="form-control"/>
        </div>
      </div>
      <div class="form-row col-md-6 col-sm-6">
        <div class="form-group col-md-8">
          <label>Currency I Want:</label>
          <select class="form-select" type="text" >
            <option value="1" selected >USD</option>
            <option value="2">EUR</option>
            <option value="3">GBP</option>
          </select>
        </div>
        <div class="form-group col-md-8">
          <label>Amount:</label>
          <input type="number" class="form-control"/>
        </div>
      </div>
      </div>
      <br/>
      <button type="submit" class="btn btn-secondary mb-2">Convert</button>
    </form>
  </div>

Thanks for the helpful solution!

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

Bootstrap 4: Embrace the seamless flow of columns with no gaps in

Recently, I encountered an issue with columns in Bootstrap 4. Despite writing the code correctly, there appears to be no space between the 3 blocks displayed in the browser. Each block consists of 4 columns, but they seem to be directly adjacent to each ot ...

My custom class is being ignored by Tailwind CSS within breakpoints

I'm attempting to incorporate some animation on the height property within the md breakpoint, but for some reason Tailwind CSS isn't applying my class. <div className={`h-12 bg-blue flex w-full text-white fixed mt-1 md:bg-white ${scrolling ? ...

Adding margin padding to a Material UI Navbar: Step-by-step guide

Hey there, I've added buttons to my Navbar from Mui. However, I'm running into an issue where the margin and padding won't change no matter what I do. I'm trying to create some space between them. Please see the code below: import { use ...

What is the proper sequence for executing a JavaScript function?

What task am I attempting to accomplish? I am trying to run two functions sequentially in JavaScript, but it seems that both functions are being called and executed simultaneously. What seems to be the issue? The setModalBox function throws an undef ...

Tips for constraining elements to set heights according to content in "stepped" increments

Is there a way to have "step-based heights" on a div? I created a small example to illustrate my question. My goal is to make sure that each box has a height that is a multiple of 400px. For instance, if a box with height: auto; is 345px, it should displa ...

Utilizing a CSS stylesheet within an ASP.NET platform

In my website, I have a reference to a CSS file like the one below: <link rel="stylesheet" type="text/css" href="http://go/css/filename.css"> Now, I want to make changes to this CSS file and upload it to a new location. Can I store the modified fi ...

Perform a check on the state of the slideToggle using an if-else function and provide a report on the slideToggle state

http://jsfiddle.net/vmKVS/ I need some help understanding the functionality of slideToggle using a small example. After toggling for the first time, the options element changes color to green. However, I expected the menu element to turn red when I togg ...

Sliding Navigation Panel

Currently, I am attempting to implement a sidebar push navigation that mimics the one showcased here. My HTML structure includes content within a center element div. The code snippet is as follows: <div id="mySidenav" class="sidenav"> <a href="j ...

What methods are available to generate dynamic shapes using HTML?

Looking to create an interactive triangle where users can move vertices or sides, updating angles in real-time. I'm struggling with how to accomplish this task. My initial attempt was to manually draw the triangle using the code below. <!DOCTYPE ht ...

Iterate through each checkbox within a specific classed div to check for selected options

Is there a way to loop through specific checkboxes with a particular class inside a div without assigning individual IDs to each one? I want to avoid the manual process of adding IDs. Below is the code snippet: JS <script> function calculate() { ...

Guide on adding dual horizontal scroll bars to a v-data-table (Vue / vuetify)

Currently, I am working on Vue / Vuetify and experimenting with the v-data-table component. While creating a table, I noticed that it has a horizontal scroll bar at the bottom. https://i.stack.imgur.com/noOzN.png My goal now is to implement two horizontal ...

Ways to hear a variable using Google Translate

We're utilizing HTML5 and Javascript. Imagine we have a list containing the names of all players from Barcelona (for example, name = 'Lionel Messi'). I want to make the player's name audible. To achieve this, I would use: var narrator ...

Challenges with CSS floating and centering in responsive design

My footer consists of 3 elements structured in the following way: <div class="footer"> <div class ="jumperMenu"> <ul> <li>1</li> <li>2</li> <li>3</li> </ul> ...

"Dynamically design a responsive mobile menu for Genesis Child Theme in Wordpress with full height

I'm in the process of designing a website for my sisters' band and I'm struggling to develop a mobile menu with full width and height in Wordpress (using PHP). The theme being used is Genesis. Can anyone provide assistance with this? Feel fr ...

Enhancing speed on an extensive list without a set height/eliminating the need for virtualization

My webapp includes a feature that showcases exhibitors at an expo. The user can click on "Exhibitors" in the navigation bar to access a page displaying all the exhibitors. Each exhibitor may have different details, some of which may or may not contain data ...

jquery expanding the width of the final element

Is there a way to increase the width of the last 'th' in a string? I want it to be the current width plus 20px. Here is the code on Fiddle var header="<th id='tblHeader_1' style='width: 80px;'><span>Id</span&g ...

Leveraging Jquery to add an element or text in front of the initial instance of a different element

Here is a sample of my xml code: <entry> <br> <abc></abc> <xyz></xyz> <example></example> <example></example> <example></example> </entry> <entry> <br> <abc>&l ...

CSS Hover Any Other Element

Is it possible to apply CSS targeting the .drop class when hovering over the .categories class only? ...

Utilize AngularJS to compile a roster of participants

Just starting out with AngularJS, and although I have some background in JavaScript, AngularJS seems quite challenging to grasp (at least for me). My current issue is as follows... I have a list of players and I want to allow users (such as coaches or an ...

"Syncing Ajax requests with JSON in synchronous mode is not functioning properly when async is

The problem I am facing is with synchronous ajax: var result = false; $.ajax({ async: false, url: url, dataType: "json", success: function(data) { ...