Suggestions for correcting the placeholders' alignment in Bootstrap 5

Currently, I am in the process of creating a registration form and experiencing some issues with spacing and positioning. How can I adjust them to be aligned on the same line in a symmetrical manner? Below is the code snippet I have added along with an image showing how it currently appears.

<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7f1d10100b0c0b0b10e07120f02233124571d13090d32">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<form>     
     <!--First Name-->
     <div class="mb-3 mt-3">
         <label for="fname" class="form-label">First name:</label>
         <input type="fname" class="form-control-xs" id="fname" placeholder="Enter name" />
     </div>
     <!--Last name-->
     <div class="mb-3 mt-3">
         <label for="lname" class="form-label">Lastname:</label>
         <input type="lname" class="form-control-xs" id="lname" placeholder="Last name" />
     </div>
     <!--Email-->
     <div class="mb-3 mt-3">
         <label for="email" class="form-label">E-mail:</label>
         <input type="email" class="form-control-xs" id="email" placeholder="Enter email" />
     </div>
     <!--Country-->
     <div class="mb-3 mt-3">
         <label for="city" class="form-label">City of residence:</label>
         <input type="city" class="form-control-xs" id="city" placeholder="City" />
     </div>
     <!--Button-->
     <input type="submit" value="Register" />
     <!--mandatory check box-->
     <input class='acb' type='checkbox' name='acheckbox[]' value='1' onclick='deRequire("acb")' required>By checking this box you agree to the
     <!--TERMS OF USE-->
     <a href="useragreement.html">user agreement</a>
     <!--PARAGRAPH-->
     <p>If you click the "Register" button, the form-data will be sent to the owner of the website.</p>
     <p>Already have an account?</p>
     <a href="../sign in/login.html"><button type="button">Sign In</button></a>
     

 </form>

view image description here

I aim to achieve a symmetrical layout where all elements are in the same line. Apologies for any grammatical errors in my request.

Answer №1

If you're looking for guidance on Bootstrap, their documentation is a great resource with plenty of examples, including one related to your specific issue. Here's the solution:

Check out the documentation here:

Bootstrap documentation

https://i.sstatic.net/9ZbhnyKN.png

* {
    margin: 0;
    padding: 0;
    font-family: "Roboto", sans-serif;
    color: #272727;
}

.register-form {
    width: 100%;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

form {
    width: 30%;
}

.form-group {
    margin-top: 5px !important;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
    <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9af8f5f5eee9eee8fbeadaafb4a9b4a9">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
</head>
<body>
    <div class="register-form">
        <form>
            <!--First Name-->
            <div class="form-group row">
                <label for="fname" class="col-sm-4 col-form-label">First name:</label>
                <div class="col-sm-8">
                    <input type="fname" class="form-control" id="fname" placeholder="Enter name" />
                </div>
            </div>
            <!--Last name-->
            <div class="form-group row">
                <label for="lname" class="col-sm-4 col-form-label">Last Name:</label>
                <div class="col-sm-8">
                    <input type="lname" class="form-control" id="lname" placeholder="Last name" />
                </div>
            </div>
            <!--Email-->
            <div class="form-group row">
                <label for="email" class="col-sm-4 col-form-label">E-mail:</label>
                <div class="col-sm-8">
                    <input type="email" class="form-control" id="email" placeholder="Enter email" />
                </div>
            </div>
            <!--Country-->
            <div class="form-group row">
                <label for="city" class="col-sm-4 col-form-label">City of residence:</label>
                <div class="col-sm-8">
                    <input type="city" class="form-control" id="city" placeholder="City" />
                </div>
            </div>
        </form>
    </div>
    
</body>
</html>

Answer №2

Utilize the power of display: grid along with grid-template-columns: subgrid:

.form-inputs {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 16px;
  align-items: center;
  label {
    margin: 0;
  }
  &>div{
    display: grid;
    grid-template-columns: subgrid;
    grid-column: span 2;
  }
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7d1f1212090e090f1c0d3d48534d534f">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<form>     
    <div class="form-inputs">
       <!--First Name-->
       <div class="mb-3 mt-3">
           <label for="fname" class="form-label">First name:</label>
           <input type="fname" class="form-control-xs" id="fname" placeholder="Enter name" />
       </div>
       <!--Last name-->
       <div class="mb-3 mt-3">
           <label for="lname" class="form-label">Lastname:</label>
           <input type="lname" class="form-control-xs" id="lname" placeholder="Last name" />
       </div>
       <!--Email-->
       <div class="mb-3 mt-3">
           <label for="email" class="form-label">E-mail:</label>
           <input type="email" class="form-control-xs" id="email" placeholder="Enter email" />
       </div>
       <!--Country-->
       <div class="mb-3 mt-3">
           <label for="city" class="form-label">City of residence:</label>
           <input type="city" class="form-control-xs" id="city" placeholder="City" />
       </div>
     </div>
     <!--Button-->
     <input type="submit" value="Register" />
     <!--mandatory check box-->
     <input class='acb' type='checkbox' name='acheckbox[]' value='1' onclick='deRequire("acb")' required>By checking this box you agree to the
     <!--TERMS OF USE-->
     <a href="useragreement.html">user agreement</a>
     <!--PARAGRAPH-->
     <p>If you click the "Register" button, the form-data will be sent to the owner of the website.</p>
     <p>Already have an account?</p>
     <a href="../sign in/login.html"><button type="button">Sign In</button></a>

 </form>

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

Guide to filling out select dropdowns in HTML with information from a database

I'm new to PHP and HTML, so please be patient with me. I've been attempting to populate a select box using data from a MySQL database, but all I see is an empty textbox. Here's my current code: <select name="cargo"> <?php ...

What is the proper way to utilize document.getElementById() within a standalone js file?

As I dive into learning web development for the first time, I've decided to keep my scripts organized in separate files. However, I'm facing a challenge when trying to access elements from these external files. Below is a snippet of the JavaScri ...

How to access elements that are dynamically added using Jquery

Similar Question: dynamic class not triggering jquery unable to select dynamically added element I am facing an issue trying to access a dynamically added element by its class name. Here is a snippet of the HTML code I am working with: <div c ...

A guide on converting an HTML tag ID to a PHP string

I am currently working on a project that is giving me some trouble with errors. I have created an HTML file called name.html and a PHP file named result.php. In the HTML file, I included some JavaScript to take us to result.php when we click on the Submit ...

`Erase content from a field once text is typed into a different field`

I have a Currency Converter with two input fields and a button. I enter the amount to be converted in the first field, and the result of the conversion appears in the second field. My question is: How can I automatically clear the second field when I type ...

Angular form array inputs

Currently delving into the world of Angular.js, I have encountered a simple problem that has left me baffled. My objective is to generate form inputs with the value of "connectedTeams" in HTML: <input type="text" name="connectedTeam[]"> <input ...

What is the best way to position a full width input beside my div element?

Having a small challenge with my CSS/HTML code, I am trying to position a full-width input next to my div. This is my HTML : <div class="leftdiv"></div> <input type="text" id="title-input" placeholder="nothing"></div> And here is ...

Retrieve the border color using Selenium WebDriver

Hey everyone, I'm currently trying to retrieve the border color of an extjs 4.2 form control text field using the getCssValue method. However, I'm having trouble getting the value as it's coming back blank. Below is a sample of my code that ...

What causes the first button to be clicked and the form to be submitted when the enter key is pressed within a text

Start by opening the javascript console, then place your cursor in the text box and hit enter. What is the reason for the function "baz" being called? How can this behavior be prevented? function foo() { console.log('foo'); } function bar() ...

I am having trouble with the Annotation Javascript library, it doesn't

After installing annotorious from the GitHub repository and following the code provided in the official documentation, I encountered an issue where the annotations were not displaying on the image as expected. Below is the HTML code that I used: <!DOCTY ...

A strategy for concealing the selected button within a class of buttons with Vanilla JS HTML and CSS

I have encountered a challenging situation where I am using JavaScript to render data from a data.json file into HTML. Everything seems to be functioning correctly, as the JSON data is being successfully rendered into HTML using a loop, resulting in multip ...

Button located beneath or above each individual image within the *ngFor loop

With the *ngFor loop, I am able to populate images but now I want to include a button below or on each image. Unfortunately, my CSS knowledge is limited. Below is the code I have: HTML Code <div class="container"> <div ...

Engage in intricate animations on Blaze

Currently seeking an effective method for implementing animations within my app using Blaze. To provide further clarification, I have included a basic example below: <template name="global"> <h1>Hello everyone!</h1> {{> foo}} ...

The overlay background is being obscured by surrounding elements

Hey there! I'm experimenting with some basic coding and ran into an issue with an overlay. Here's the site link: Sorry for the strange language. :-) If you click on the button with the tiny icon, you'll notice that the overlay form isn&apos ...

Are PostbackUrl and Form.Submit the same thing?

Recently, I took over a project that utilized form submissions to send data. Unfortunately, I am not well-versed in how forms work. It seems like such an outdated way of submitting data. Moreover, converting these forms into MasterPages causes them to brea ...

What is the method for applying a prefix to component tags in Vue.js?

Currently, I am tackling a project that was passed down to me and have noticed numerous <p-xxxx> tags scattered throughout the codebase, such as <p-page :has-something="val1" :has-another="val2" />, etc. (For example: CompName --> After a b ...

Having trouble with the repeat-item animation feature not functioning correctly

Take a look at this Plunker, where the animation for adding an item only seems to work properly after an item has been deleted from the list. Any suggestions on how to resolve this issue? Here is the CSS code: .repeat-item.ng-enter, .repeat-item.ng-leave ...

Organizing the <tr> element within a panel control in asp.net

I am experiencing some difficulty trying to insert content inside the panel control in asp.net. For some reason, it is not allowing me to do so. Below is the code snippet I have been working with. Any help or insight on this issue would be greatly apprec ...

how can I use jQuery to disable clickable behavior in HTML anchor tags?

Here is the HTML code I am working with: (note -: I included j library on the top of page ) <div class="WIWC_T1"> <a href="javascript:void(0);" onClick="call_levelofcourse();popup('popUpDiv1')">Level of Course</a> </di ...

Tips for making nested sliding divs within a parent sliding div

Is it possible to slide a float type div inside another div like this example, but with a white box containing "apple" text sliding inside the black div it's in? I have attempted to recreate the effect using this example. Here is my current JavaScript ...