Struggling to properly center my login form and give it an attractive, sleek card design

Looking to create a login form similar to the one shown in this image using Bootstrap5, but struggling to do so. Is there anyone who can assist me in creating a login form like the one mentioned here? I am new to Bootstrap and CSS.

Here is my current template:

<div class="container">
    <div class="text-center">
    {% for message in messages %}
    <h5>{{ message }}</h5>
    {% endfor %}
    <br>
    </div>
</div>

<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-6">
            <div class="card">
            <form method="POST" action="{% url 'login' %}">
                {% csrf_token %}
                <div class="form-group">
                    <label class="text-primary">Enter Username</label>
                    <input type="text" class="form-control" name="username">
                </div>
                
                <br>
                <div class="form-group">
                    <label class="text-primary ">Enter Password</label>
                    <input type="password" class="form-control" name="password">
                </div>
                <br>
                <button type="submit" class="btn btn-primary">Login</button>
            </form>
        </div>
        </div>
    </div>
</div>

Answer №1

After incorporating a few more classes from their library, the design started to come together nicely. One class in particular, font-weight-bold, wasn't initially working, so I had to add it as custom CSS. It seems like the functionality may vary depending on the version of Bootstrap being used.

.container {
  background: #1D8FF9;
  padding: 10rem 0;
}
.font-weight-bold {
  font-weight: 600;
}
.btn-block {
  display: block!important;
  width: 100%;
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="75171a1a01060107140535405b445b46">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"/>

<!--<div class="container">
    <div class="text-center">
    {% for message in messages %}
    <h5>{{ message }}</h5>
    {% endfor %}
    <br>
    </div>
</div>-->

<div class="container p-10">
    <div class="form-container">
      <div class="row justify-content-center align-content-center">
          <div class="col-md-6">
              <div class="card p-5">
              <h2 class="text-center">Sign In</h2>
              <br>
              <form method="POST" action="{% url 'login' %}">
                  <!--{% csrf_token %}-->
                  <div class="form-group">
                      <label class="text-primary text-dark font-weight-bold">Enter Username</label>
                      <input type="text" class="form-control" name="username" placeholder="Enter Email">
                  </div>

                  <br>
                  <div class="form-group">
                      <label class="text-primary text-dark font-weight-bold">Enter Password</label>
                      <input type="password" class="form-control" name="password" placeholder="Enter Password">
                  </div>
                                    <br>
                  <div class="form-check">
    <input type="checkbox" class="form-check-input" id="exampleCheck1">
    <label class="form-check-label" for="exampleCheck1">Remember Me</label>
  </div>
                  <br>
                  <button type="submit" class="btn btn-primary btn-block">Submit</button>
              </form>
          </div>
          </div>
      </div>
   </div>
</div>

Answer №2

Your design example is great, but I suggest starting with CSS to build a solid foundation. Focus on mastering CSS Grid and Flexbox first before moving on to Bootstrap - it will make learning much easier.

body {
  background: #f5f6f9;
}

.card {
  border-radius: 10px;
  border: 0;
  box-shadow: rgba(0, 0, 0, 0.16) 0px 1px 4px;
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="87e5e8e8f3f4f3f5e6f7c7b2a9b7a9b5">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
  <div class="d-flex align-items-center justify-content-center min-vh-100">
    <div class="col-xl-4">
      <div class="card py-4 px-3">
        <h3 class="text-center fw-bold">Sign In</h1>
          <div class="mt-3">
            <form action="" method="post">
              <div class="col-xl-12">
                <div class="mb-3">
                  <label for="exampleFormControlInput1" class="form-label">Email address</label>
                  <input type="email" class="form-control" id="exampleFormControlInput1" placeholder="Enter email">
                </div>
                <div class="mb-3">
                  <label for="exampleFormControlInput1" class="form-label">Password</label>
                  <input type="email" class="form-control" id="exampleFormControlInput1" placeholder="Enter password">
                </div>
                <div class="form-check mb-3">
                  <input class="form-check-input" type="checkbox" value="" id="flexCheckDefault">
                  <label class="form-check-label" for="flexCheckDefault">Remember me</label>
                </div>
                <div class="mb-3">
                  <button class="btn btn-primary w-100">Submit</button>
                </div>
                <div class="d-flex justify-content-end">
                  <a href="#">Forgot password?</a>
                </div>
              </div>
          </div>
          </form>
      </div>
    </div>
  </div>
</div>
</div>

Hopefully this advice helps you in your design journey :)

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

Altering an element's visibility from 'none' will trigger its animation to play once again

Take a look at the snippet below and you'll see that the sliding animation plays twice - once when the .addClass statement runs, and again when #test's display is switched to 'initial' (timeouts are in place to help visualize the issue) ...

Conceal a list of items within a div that has a particular class

This is a sample of my HTML code: <div class="row"> <div class="col-md-12"> <div class="scrollbox list"> <ul class="list-unstyled"> <li id="articulate.flute">articulate flut ...

Tips on aligning two divs vertically within an HTML <li> element, even with content that varies in size, by utilizing nested flexboxes

Every div contains unique content of varying heights. Our approach involves using flexboxes to ensure equal height for each li element. Now, we are facing a challenge with positioning the div class="2" so that their tops align perfectly. We've expe ...

Searching dynamically using class names with JQuery

I am seeking to create a dynamic search input based on the class names within the span tags. However, I am struggling with displaying the class name that I have identified. My goal is to show the class names that match the entered value in the input on the ...

Looking for a solution to resolve the issue "ERROR TypeError: Cannot set property 'id' of undefined"?

Whenever I attempt to call getHistoryData() from the HTML, an error message "ERROR TypeError: Cannot set property 'id' of undefined" appears. export class Data { id : string ; fromTime : any ; toTime : any ; deviceType : string ...

Toggle visibility of anchor tags on screens with lower resolution

Looking for help with my code <div id="contact-buttons-bar" class="slide-on-scroll" data-top="250px" style="left: 0px;"> <button class="contact-button-link show-hide-contact-bar" style="left: 0px;"> <a class="contact-button-link cb-ancor f ...

Sliding Dropdown Menu with Dynamic Title Change Upon Selection

I'm having an issue with a dropdown menu on hover that slides down and then back up. The active list item serves as the title of the dropdown. When a user clicks on an <li>, it becomes active and receives the class active-markup-style which sets ...

Alter the background-color of the parent div when an input is checked using CSS

.chk-circle { width: 8px; height: 8px; background: #afb0b5; border-radius: 100%; position: relative; float: left; margin-top: 4px; margin-right: 8px; } .chk-circle label { display: block; wi ...

Implementing React inline styles by directly incorporating brackets into the HTML rendering

I'm working on a project in React using create-react-app and trying to apply an inline style. Based on my research, the following line of code should work fine: <div id="root" style={{ height: 'auto' }}></div> However, when I r ...

What is the best way to extract pricing information from Udemy?

Important: I haven't been able to find a relevant solution in similar questions. How can I extract prices from Udemy using web scraping? Scraping Data From Udemy's AngularJs Site Using PHP How do I obtain promotional prices using the Udemy API ...

How can we add a class to a radio button using jQuery when it is checked, and remove the class when it

I'm looking for help with using jQuery to toggle between two radio buttons and display different divs based on the selection. jQuery(document).ready(function($) { if ($('#user_personal').is(':checked')) { $('.user_co ...

Ways to incorporate padding into md-card using Angular 2 material

Need assistance with adding padding to md-card in angular2 material. I am using md-card to display my product list but struggling to add padding on them. Here's what I have tried: product.component.html : <p> Product List </p> <div ...

Why does Typeahead display a JSON object in the input field upon clicking?

My suggestion engine is working well, but I am facing an issue where the json object appears in the input element when I click on an item. I want only the OrgName to show up in the input value. <input class="form-control companySearch" type="text" valu ...

When the user clicks on the iframe, they will be redirected to the

My goal is to create a scenario where clicking on an iframe opens the same URL in a new browser tab, while ensuring that scroll and other mouse events within the iframe are not affected. I have experimented with various approaches but none have been succe ...

Visual Studio Code version 1.42 is now automatically converting <br> tags to <br /> when formatting code

This issue just started occurring. I'm not exactly sure what triggered it, but it could be related to my attempt to activate the Preitter extension. As a newcomer to Visual Studio Code, I am currently working on HTML5 documents. Strangely, whenever I ...

Utilizing PHP to fetch data from a separate webpage

This is a question that has sparked my curiosity. I am not facing any particular issue that requires an immediate solution nor do I possess the knowledge on how to achieve it. I have been contemplating whether it is feasible to utilize PHP for fetching co ...

Tips for utilizing FixedHeaderTable - Basic instructions required

After doing extensive research, I stumbled upon this plugin called Fixed Header Tables. Despite following the instructions provided on the main website, I couldn't get it to work. I was aiming to create a table with a fixed top row and left column fu ...

Tips for verifying if the input in a Material UI textfield is an <iframe> tag

In my ReactJS code, I am utilizing the TextField component from material-ui. I need to verify if the user input is an iframe. How can I achieve this? Currently, I am attempting to use window.parent.frames.length > 0; to determine if the page contains a ...

Postponing the activation of toggleClass in jQuery until the completion of a slide animation

Having some trouble with the jQuery delay() function. I'm using it to pause a toggleClass action until after a slideUp animation on one of my divs, but it doesn't seem to be working as expected. I want a bar with rounded corners that expands whe ...

Using jquery and Ajax to extract data from nested JSON structures

Need help with modifying a code snippet for parsing nested JSON format [ { "name":"Barot Bellingham", "shortname":"Barot_Bellingham", "reknown":"Royal Academy of Painting and Sculpture", "bio":"Barot has just finished his final year at T ...