When a div is added, the alignment of Bootstrap 4 elements becomes skewed

Desired Appearance:

https://i.sstatic.net/jYCiq.png

Undesired Appearance:

https://i.sstatic.net/m3emV.png

I recently encountered an issue with my registration form where it started to look different from my login form even though I only added extra fields. I wanted both forms to have a consistent design, so I tried troubleshooting with online resources but couldn't find a solution. As I'm currently learning Django, I took extra care to make sure the forms looked visually appealing and cohesive. However, I faced confusion when my additional fields caused unexpected layout changes. I aim to understand and rectify this issue, as striving for consistency and clarity in design is essential to me.

Below is the HTML code for my index page and login form:

<!-- HTML code for index page and login form -->

Furthermore, I included the registration form code using the same CSS and bootstrap method:

<!-- HTML code for registration form -->

Lastly, here is the CSS code I utilized for styling the forms:

<!-- CSS code for styling forms -->

Answer №1

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

body {
  background: rgb(211, 218, 218);
}
.row {
  background: white;
  border-radius: 30px;
  box-shadow: 12px 12px 22px;
}
img {
  border-top-left-radius: 30px;
  border-bottom-left-radius: 30px;
}
.btn1 {
  border: none;
  outline: none;
  height: 50px;
  width: 100%;
  background-color: black;
  color: white;
  border-radius: 4px;
  font-weight: bold;
}
.btn1:hover {
  border: none;
  outline: none;
  height: 50px;
  width: 100%;
  background-color: rgb(51, 105, 38);
  color: white;
  border-radius: 4px;
  font-weight: bold;
}
<!DOCTYPE html>
<html lang="en>
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8>
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/ [email protected] /dist/css/bootstrap.min.css"
      integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2"
      crossorigin="anonymous">

    {% load static %}
    <link rel="stylesheet" href="{% static 'styles.css' %}" />

    <title>Albert's Page</title>
  </head>
  <body>
    <section class="Form my-4 mx-5">
      <div class="container">
        <div class="row no-gutters">
          <div class="col-lg-5">
            <img
              src="https://images.unsplash.com/photo-1602900004353-2e786ce8f35c?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=658&q=80"
              alt=""
              class="img-fluid">
          </div>
          <div class="col-lg-7 px-5 pt-5">
            <h1 class="font-weight-bold py3">Registration Form</h1>
            <h4>Sign up for an account</h4>
            <form action="" method="post">
              <div class="form-row">
                <div class="col-lg-7">
                  <h4>Your Full Name</h4>
                  <input
                    type="fullName"
                    name="fullName"
                    class="form-control my-3 p-4">
                </div>
              <!-- I added below </div> tag here. only one change and it works. -->
              </div>
              <!-- Change Ended. -->                    
                <div class="form-row">
                <div class="col-lg-7">
                  <h4>User Name</h4>
                  <input
                    type="userName"
                    name="userName"
                    class="form-control my-3 p-4">
                </div>
              </div>
              <div class="form-row">
                <div class="col-lg-7">
                  <h4>Password</h4>
                  <input
                    type="password"
                    name="pw"
                    class="form-control my-3 p-4">
                </div>
              </div>
              <div class="form-row">
                <div class="col-lg-7">
                  <h4>Confirm Password</h4>
                  <input
                    type="password"
                    name="cpw"
                    class="form-control my-3 p-4">
                </div>
              </div>
              <div class="form-row">
                <div class="col-lg-7">
                  <button class="btn1 mt-3 mb-5" type="submit">Register</button>
                </div>
              </div>

              <p>Have an account then <a href="/">Sign In</a></p>
            </form>
          </div>
        </div>
      </div>
    </section>

    <!-- Option 1: jQuery and Bootstrap Bundle (includes Popper) -->
    <script
      src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
      integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
      crossorigin="anonymous"></script>
    <script
      src="https://cdn.jsdelivr.net/npm/ [email protected] /dist/js/bootstrap.bundle.min.js"
      integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx"
      crossorigin="anonymous"></script>
  </body>
</html>

Answer №2

To address your query, you can utilize the following solution. Begin by incorporating the crispy form tag at the beginning of the index page. Prior to using crispy form tags, ensure that you have installed them by executing the following command:

pip install django-crispy-forms

After installation, include the following code at the top of the index page, any page where the form is located, or in the base.html page:

{% load crispy_forms_tags %}

Generate your forms in a separate file named forms.py, where you can define your forms using Python classes. Then, import these forms into the views.py file and transfer them to HTML pages as variables.

In your HTML pages, structure your form using the following format:

<form action="some_url">
{{ form | crispy }} <!-- The 'form' variable represents the class that was used to create the form in forms.py -->
</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

Setting the class attribute dynamically using code behind

Below is a snippet of code I am working with: div1.Attributes.Add("class", "displayNone"); It functions properly during page load but fails to do so during an OnClick event. The issue arises from the fact that my HTML element <div id="div1"></d ...

Command 'python manage.py syncdb' fails to generate tables

My initial step was running python manage.py syncdb which successfully created the database and tables. Next, I wanted to add more apps, so here's what I did: I created a new app using the command: python manage.py startapp newapp After creating ...

Unleash the Power of Your Webpage: Instantly Engage Full

Is there a way to automatically make a webpage open in full screen mode as soon as it is loaded? Here's what I currently have: var elem = document.documentElement; function openFullscreen() { if (elem.requestFullscreen) { elem.requestFull ...

Display the div element only when the mouse is hovering over the button

I need a hidden text inside a div that will only appear when the mouse pointer is hovering over a specific button. Here is my current code: // Show help-text on hover $("#help-container") .mouseover(function(e) { $(this).find("#help-t ...

Struggle with the background div menu

I am trying to create a menu with a background color, but when I use "background" or "background-color" on the div that contains my menu, I can't see any color. It's frustrating because I know it should be working.. Here is the HTML : <head ...

Personalize the color scheme for your timeline paper

I am interested in customizing this specific example of a personalized timeline: import React from 'react'; import { makeStyles } from '@material-ui/core/styles'; import Timeline from '@material-ui/lab/Timeline'; import Timeli ...

Building dynamic web applications using React.js and Django without the need for webpack

Exploring the idea of integrating React components into a Django project has been on my mind. The plan is to leverage React for specific features, such as filters and search boxes. After perusing a similar inquiry on Stack Overflow, I realized the suggest ...

MUI Datepicker options for selecting dates

Is there a way to selectively enable certain dates and disable all others in the MUI Datepicker? For example, I need to only allow dates that are 7 days later or earlier to be selectable, while all other dates should be disabled. How can this be achieved? ...

Is it acceptable to include a checkbox and a hidden input within a label element?

When creating a list of possible products for users to buy, I use the ul tag combined with li. Each product element includes a checkbox that allows users to select the product or not. For products with related information, I want to store this data in a h ...

How can I fix the alignment issue with my centered div?

My attempt to vertically align a centered inner DIV is not working as expected... What could be causing this issue? CSS Code: #page_bar { width: 100%; height: 30px; background-color: white } .page_bar { width: 800px; height: 30px; ...

What steps should I take to design a mobile-friendly navigation bar?

I have shared the code for my navigation bar in a previous post Fixing Nav Bar to top of page. Now, I want to create a mobile version of it, but I am new to designing for mobile devices. Based on feedback and some CSS tweaking, I have managed to make it wo ...

Tips for configuring Django logs on Heroku to write to an external log file

To enhance my analysis capabilities, I am looking to record and store all requests/responses. Given that Heroku is an ephemeral system, I have decided to log the data directly to AWS (leveraging s3boto for media files). Despite attempting to utilize pyth ...

Tips on creating adaptable images for mobile viewing

My coding conundrum involves the use of two columns - one for an image and the other for a description of that image. However, when viewing my site on mobile devices, the image is cut off at only half its height. Adjusting both columns to col-sm-6 results ...

Stop Ajax requests when there are blank spaces in Typeahead.js

I've been experimenting with typeahead.js and utilizing the BloodHound remote feature to load data. Everything is functioning properly, except that when I input only spaces in the textbox, typeahead still makes an ajax call. I'm wondering if th ...

What is the best way to convert JSON data to HTML format?

I have a JSON file with the following data: [ { "key1": "value1", "key2": "value2" }, { "key3": "value3", "key4": "value4" }] The desired output format is: <h1>value1</h1><p>value2</p><h1>value3</h1><p>value4< ...

How to position an absolute div in the center of an image both vertically and horizontally

Can someone help me figure out how to center a div inside an image? I seem to be having trouble with the positioning and alignment. Any suggestions or advice would be greatly appreciated. Thanks! .template-banner{ width: 100%; height: auto; margin: 0; } ...

The Stylish Choice: Materialize CSS Dropdown Selector

I am currently integrating Materialize CSS into my application and have used media queries to ensure that the layout is responsive. However, I am facing an issue with a select dropdown element. It works fine on laptops but does not allow for selecting any ...

Ways to set a default image for an <img> tag

I am looking to set a default image to the img tag in case the user has not selected a profile picture for their account. Here is the current output: http://jsfiddle.net/LvsYc/2973/ Check out the default image here: This is the script being used: funct ...

Issue with iOS 10: Changes to class not reflected in CSS/styles

Currently, I am utilizing Ionic with Angular to develop an application for Android and iOS. Surprisingly, everything functions smoothly on Android, but there seems to be an issue with iOS. I am employing a class change on an element using ng-class. I can ...

CSS fails to display image within PHP script

Having an issue with displaying CSS through a PHP file. Everything seems to be working fine until I try to display an image from the database. The source code does accept the value from the DB, but the image doesn't show up. Interestingly, the image d ...