`Position the login page contents in the center`

Having some difficulty centering the content on my login page. Can you assist with styling? I would like to have the input fields centralized and compact, similar to a standard login page. Also, I am encountering an issue with using different Bootstrap versions for various components in my project. Is there a workaround for this?

Here is the code snippet:

{% extends "auctions/layout.html" %}

{% block body %}


    <h2>Login</h2>

    {% if message %}
        <div>{{ message }}</div>
    {% endif %}

    <form action="{% url 'login' %}" method="post">
        {% csrf_token %}
        <div class="form-group">
            <input autofocus class="form-control" type="text" name="username" placeholder="Username">
        </div>
        <div class="form-group">
            <input class="form-control" type="password" name="password" placeholder="Password">
        </div>
        <input class="btn btn-primary" type="submit" value="Login">
    </form>

    Don't have an account? <a href="{% url 'register' %}">Register here.</a>

{% endblock %}

Answer №1

Take a look at this code snippet:

    <div class="container">
        <div class="row justify-content-center">
            <div class="col-3 text-center">
                    <h2>Login</h2>

    {% if message %}
        <div>{{ message }}</div>
    {% endif %}

    <form action="{% url 'login' %}" method="post">
        {% csrf_token %}
        <div class="form-group">
            <input autofocus class="form-control" type="text" name="username" placeholder="Username">
        </div>
        <div class="form-group">
            <input class="form-control" type="password" name="password" placeholder="Password">
        </div>
        <input class="btn btn-primary" type="submit" value="Login">
    </form>
*emphasized text*
    Don't have an account? <a href="{% url 'register' %}">Register here.</a>
            </div>
        </div>
    </div>

Answer №2

Take a look at this resource that might be useful for you: Bootstrap flex method

{% extends "auctions/layout.html" %}
    
    {% block body %}
      
       <div class="container">
        <div class="row justify-content-center mt-5">
        <div class="col-md-6 text-center">
    
        <h2>Login</h2>
    
        {% if message %}
            <div>{{ message }}</div>
        {% endif %}
    
        <form action="{% url 'login' %}" method="post">
            {% csrf_token %}
            <div class="form-group">
                <input autofocus class="form-control" type="text" name="username" placeholder="Username">
            </div>
            <div class="form-group">
                <input class="form-control" type="password" name="password" placeholder="Password">
            </div>
            <input class="btn btn-primary" type="submit" value="Login">
        </form>
    
        Don't have an account? <a href="{% url 'register' %}">Register here.</a>
       </div>
      </div>
     </div>
    
    {% endblock %}
  

Answer №3

Employed this method and it was successful

<style>
    body {
        text-align: center;
    }
    form {
        display: inline-block;
    }
</style>

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

Sending values from buttons to different Django templates/views

Initially, the user provides a CSV file. (Template File:) <form method="post" action="{% url 'rowcol' %}" enctype="multipart/form-data"> {% csrf_token %} <input type="file" name="file" accept=".csv"> <button type="sub ...

Is there a way for me to view the contents within the box?

Hey there! I have a question about how to access the content inside this mysterious box "" within the style sheet. For instance, I am curious to find out the link of the image: .facebookicon::before { content: ""; } ...

Django: Showing a collection of interconnected information to the user currently logged in

I need to present data retrieved from my database in a specific format: User collection of emails Currently, my setup looks something like this: models.py class Person(models.Model): name = models.CharField(max_length=50) surname = models.Char ...

HTML Master Page - Working on eliminating empty space

While working on my ASP.NET project for class, I seem to be encountering an issue with a mysterious blank space. Despite checking for breaks, margins, and padding throughout the code, I can't pinpoint the source of this unwanted gap. The blank space a ...

Is it possible to alter the cursor according to the position of the mouse?

Is it possible to change the cursor from default to pointer when the mouse enters the specific rectangle area (50, 50, 100, 100) of the body? The dimensions are in pixels. Instead of defining a separate div and setting the cursor style on it, I'm loo ...

iterative outcomes with ajax and jquery scripting in javascript

Hey there! I'm trying to create a JavaScript script using AJAX that will extract the id and value of a button when hovered over. The extracted value will then be sent to a PHP script on the same page, where it will be used as a variable for searching ...

Updating the checklist status using an ajax request: A step-by-step guide

Is it better to update the checklist status by making individual ajax calls for each checklist item or by making one call and updating it once completed? I have included a template showing how it currently looks and what I am aiming for. Unfortunately, I ...

Maintaining divs in a row with Bootstrap 4

I need help with a list item containing two divs. I want the div with the checkmark to always stay on the left side even when the screen is resized. Currently, on smaller screens, the divs stack on top of each other. <ul> <li class="comment"& ...

The calendar on the Datetimepicker is not appearing in the proper position

I have encountered an issue while using Eonasdan bootstrap datetimepicker in a paramquery grid. Whenever I open the datetimepicker, the calendar appears hidden inside the grid. To tackle this problem, I added the following CSS condition: .dr ...

Unable to display images on mobile devices using HTML

I recently created a website using HTML and CSS. I have successfully added images to some of the web pages, and they display properly on laptops and desktops. However, I am facing an issue where the images do not appear on small screens, even though all im ...

Tips for aligning text in the middle of a customizable and adjustable button with the use of only Bootstrap 4

I am encountering an issue with button text alignment. After customizing the width and height of a button, I noticed that its text does not remain centered on certain screen sizes while in debugging mode. Html <!doctype html> <html lang="en> ...

Modify the MUI Select icon background color on hover

I have been working on customizing the MUI Select method, and I've encountered difficulty when trying to hover over the "NarrowDownIcon": https://i.sstatic.net/VEZFP.png My goal is to change the hover behavior of this icon by setting its backgroundC ...

The hyperlink to a different webpage does not trigger any JavaScript functionalities or render any CSS styles

I am facing an issue with linking HTML pages that run Javascript and JQuery Mobile from another HTML page. My link setup is as follows: <a href="hours.html">Hours</a> The linking page and the linked pages are in the same directory. However, ...

JavaScript and CSS tabs with smooth transition effect

I want to create tabs that smoothly fade between each other when switching. The code I have works, but there's a slight issue. When transitioning from one tab to the previous one, there is a momentary glitch where the last tab briefly changes state be ...

What causes Font Awesome 5 icons to vanish when changing the font-family?

I am facing an issue with the code I have below. It changes the font style successfully, but it also causes the icon to disappear. Can anyone provide tips on how to ensure that the icon remains visible while changing the font style? <link rel="styles ...

What is the best way to design a three-color column layout without any text?

I am attempting to design a three-color column layout using Bootstrap without any text. I have successfully created the columns with the desired colors, but I am facing an issue regarding how to remove the text without affecting the size of the columns. W ...

Turn off hover opacity effect for a specific image

Currently, I've implemented a hover opacity effect on my images using the following CSS: img { opacity: 1.0; filter: alpha(opacity=1.0); } img:hover { opacity: 0.6; filter: alpha(opacity=0.6); } However, I now have a specific image for whi ...

Arranging Bootstrap columns based on click action

How can I rearrange the order of columns using bootstrap and jQuery when clicked? I've tried to implement this functionality for the left button, but it doesn't seem to be working as expected: $("#left").on("click", function() { ...

Ways to execute a task based on various selection option values?

Is there a way to dynamically change the API key value based on the selected currency option? For example, I want to display prices in different currencies like INR, USD, EUR, etc., each requiring a different API key. <select class="form-select for ...

How can I use jQuery to prevent a click function from running when input fields are left empty

I have step cards with input fields on each card. A "Next" button is provided for each card to change the view. However, I need to prevent the "Next" button from functioning if any input fields on the form are left empty. Below is the code snippet: va ...