Arrange form elements with Bootstrap 5 styling

Seeking assistance with creating a mobile login page using Bootstrap 5 and custom CSS. Struggling to align form items inside the form properly. Any suggestions on how to achieve this?

.row {
  height: 100vh;
  justify-content: center;
  align-items: center;
  /* border: solid 3px black; */
}

.card {
  height: 380px;
  width: 100%;
  background-color: aliceblue;
  /* border: solid 3px green; */
}

.card-body {
  height: 80%;
  width: 100%;
  /* border: solid 3px red; */
}

.form-content {
  height: 100%;
  width: 100%;
  /* border: solid 3px blue; */
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

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

  <title>Document</title>
</head>

<body>

  <div class="container-fluid">
    <div class="row">
      <div class="col-12">
        <div class="card">
          <div class="card-body">
            <form class="form-content">
              <div class="form-group">
                <label for="userEmail" class="form-label">Email address</label>
                <input type="email" class="form-control" id="userEmail" aria-describedby="emailHelp">
              </div>
              <div class="form-group">
                <label for="userPass" class="form-label">Password</label>
                <input type="password" class="form-control" id="userPass">
              </div>
              <div class="form-group">
                <button type="submit" class="btn btn-primary">Submit</button>
              </div>
            </form>
          </div>
        </div>
      </div>
    </div>
  </div>
  <style>
    .row {
      height: 100vh;
      justify-content: center;
      align-items: center;
      /* border: solid 3px black; */
    }
    
    .card {
      height: 380px;
      width: 100%;
      background-color: aliceblue;
      /* border: solid 3px green; */
    }
    
    .card-body {
      height: 80%;
      width: 100%;
      /* border: solid 3px red; */
    }
    
    .form-content {
      height: 100%;
      width: 100%;
      /* border: solid 3px blue; */
    }
  </style>

  <script src="https://cdn.jsdelivr.net/npm/@popperjs/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a7c4c8d5c2e7958996978899">[email protected]</a>/dist/umd/popper.min.js" integrity="sha384-7+zCNj/IqJ95wo16oMtfsKbZ9ccEh31eOz1HGyDuCQ6wgnyJNSYdrPa03rtR1zdB" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="20424f4f54535452415060150e110e13">[email protected]</a>/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>
</body>

</html>

Any help or guidance would be greatly appreciated!

Answer №1

How would you like it aligned?

If you prefer center alignment, apply the following properties to your form tag in CSS:

display: flex;
flex-direction: column;
align-items: center;
justify-content: center;

Alternatively, in Bootstrap, add these classes to your form:

<form class="d-flex-col justify-content-center align-items-center">

Answer №2

For your second and third form-group classes, you can simply include the mt-2 class. This addition will apply a half-rem margin to each specified area.

.row {
  height: 100vh;
  justify-content: center;
  align-items: center;
  /* border: solid 3px black; */
}

.card {
  height: 380px;
  width: 100%;
  background-color: aliceblue;
  /* border: solid 3px green; */
}

.card-body {
  height: 80%;
  width: 100%;
  /* border: solid 3px red; */
}

.form-content {
  height: 100%;
  width: 100%;
  <!-- border: solid 3px blue; -->
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

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

  <title>Document</title>
</head>

<body>

  <div class="container-fluid">
    <div class="row">
      <div class="col-12">
        <div class="card">
          <div class="card-body">
            <form class="form-content">
              <div class="form-group">
                <label for="userEmail" class="form-label">Email address</label>
                <input type="email" class="form-control" id="userEmail" aria-describedby="emailHelp">
              </div>
              <div class="form-group mt-2">
                <label for="userPass" class="form-label">Password</label>
                <input type="password" class="form-control" id="userPass">
              </div>
              <div class="form-group mt-2">
                <button type="submit" class="btn btn-primary">Submit</button>
              </div>
            </form>
          </div>
        </div>
      </div>
    </div>
  </div>
  <style>
    .row {
      height: 100vh;
      justify-content: center;
      align-items: center;
      /* border: solid 3px black; */
    }
    
    .card {
      height: 380px;
      width: 100%;
      background-color: aliceblue;
      /* border: solid 3px green; */
    }
    
    .card-body {
      height: 80%;
      width: 100%;
      /* border: solid 3px red; */
    }
    
    .form-content {
      height: 100%;
      width: 100%;
      /* border: solid 3px blue; */
    }
  </style>

  <script src="https://cdn.jsdelivr.net/npm/@popperjs/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="53303c213613617d62637d61">[email protected]</a>/dist/umd/popper.min.js" integrity="sha384-7+zCNj/IqJ95wo16oMtfsKbZ9ccEh31eOz1HGyDuCQ6wgnyJNSYdrPa03rtR1zdB" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="96f4f9f9e2e5e2e4f7e6d6a3b8a7b8a5">[email protected]</a>/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>
</body>

</html>

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

Ways to showcase the outcome of a spin after each rotation

I am currently working on a spinning code snippet that allows users to spin and potentially win different amounts. The code includes functionality to prevent more than 3 spins, set random rotation values, and animate the spinning effect. However, I now wa ...

Crafting a visually appealing CSS menu

Recently began my journey into web development, and I'm eager to replicate the style of this navbar. Can someone guide me on how to stylize a navigation bar list item for a single element? I am determined to learn and appreciate any help provided. Tha ...

Ways to showcase HTML table in a four-column layout/grid

Delving into Dynamic HTML table creation, I'm currently using jquery for rendering purposes. At the moment, I am only displaying the table. The Goal I aim to segment my table into four columns or a grid structure Something akin to this: https://i. ...

Generate a new table based on the decreasing total of rows from the initial table

I have initially created a table using the rcm.create() method. Now, I need to create another table where the rows are ordered based on the descending sum of the rows from the first table. To achieve this, I will utilize the rcm.generateTab2() method which ...

The div is lacking in height

I have 3 divs that belong to the stackContainer class: .stackContainer { position: relative; } Within these divs, I want multiple elements stacked on top of each other. To achieve this, I use the following code: .stackItem { position: absolute; ...

How can I assign a unique background color to each individual column within a RadioButtonList?

I have an issue with setting 3 repeated columns. I want to assign different background colors to each of them. If you have any ideas on how I can achieve this, please share. Here is the code for my RadioButtonList: <asp:RadioButtonList ID="rblTimeSlot ...

Guide to triggering a popover from within another popover using jQuery

Currently, I have a situation where a popover is triggered by clicking on a button. The goal is to trigger another popover from the first popover by clicking on some content within it. If you'd like to see a demonstration, check out this JSFiddle lin ...

Issue with Brave browser: CSS animations not functioning properly, although they work perfectly in Firefox

Link to Codepen: https://codepen.io/sabeser/pen/RwYzJpd HTML: <div id='wrapper'> <div class='circle'></div> <div class='circle'></div> </div> CSS: :root { --scale--rati ...

Transformation of visuals with alteration of status

I am attempting to change the image of a door from closed to open when the status changes in my home automation dashboard. I need help with this task. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&qu ...

Is there a way for me to prioritize the sidebar over the main content on the page

My theme is efficient and visually appealing, but there's one issue with the mobile layout - it displays the sidebar after the content. How can I rearrange this in my theme so that the sidebar appears before the content? Thanks for your help! ...

create a word with only **one** bold letter in the word ionic-angularjs

Can someone please guide me on how to style only a specific letter within a word using angularJS? Specifically, I want to make the first letter bold while keeping the rest of the word in normal font. For instance, if I have an array of words like: var Wor ...

Issues with padding and margin on iOS devices

On my iPhone (iPhone 6, iOS 8), I noticed that the loader is positioned slightly above the button. However, when I use the Chrome mobile emulator, I can't see this issue. I'm puzzled about how to resolve it. What do you think could be causing thi ...

Can PHP be incorporated with vBulletin seamlessly?

I am looking to seamlessly integrate vBulletin into a PHP page. I don't want to create a skin that simply matches the site's appearance, but rather have the forum fully integrated with the site. Of course, the skin would need to be modified to ma ...

Enhance your website with a unique hover and left-click style inspired by the functionality of file explorer

I have a set of items like this: I am trying to replicate the functionality of a file explorer in terms of item selection. To clarify, I aim to create a feature where hovering over an item and left-clicking it would generate a virtual rectangle to select ...

Struggling with CSS issues in ASP.NET 4.6

For the past few months, I've been diligently working on a project that suddenly hit a snag today. Upon inspecting my website, I noticed that all my button sizes appear to be uniform. I typically use Chrome's developer tools to troubleshoot my we ...

Overflow-y SweetAlert Icon

Struggling with a website modification issue where using Swal.fire(...) causes an overflow problem affecting the icon rendering. How can this be fixed? Here is the custom CSS code in question: * { margin: 0px; padding: 0px; font-family: &ap ...

A space has been included before the CSS tag in the document for docx4j/Js

I am looking for a way to convert an HTML formatted string into a docx file. Currently, I am using Jsoup to clean up the HTML and then docx4j to parse the XHTML into a docx format. However, I encountered an issue with colors since they are not supported b ...

How to manage the three states (InProgress, Success, Error) of a dropdown dynamically in AngularJS with ng-show/hide?

Currently, I have implemented a bootstrap dropdown that loads a list of countries by making an external API call. My goal is to display three different states of behavior (progress, success, error) in the dropdown using ng-show/hide. However, I am unsure h ...

Moving the mouse over a div will alter the heading of another div

Trying to find a solution for a unique problem. I have 5 boxes and need to style one box with a different heading color. As I hover over the other 4 boxes, I want the active box heading to change to a new color. The color should remain even after moving th ...

Adjust image size according to the browser's window resize using JQuery

I am trying to make an image resize based on the browser size changes using JQuery. My goal is for the image to scale without losing its aspect ratio or getting cropped. I have incorporated Bootstrap in my HTML structure: <div class="container-fluid" ...