Is there a way to vertically center the form in order to position the logon at the top center?

https://i.sstatic.net/8gdCo.png

Looking to vertically center align the login form. I've tried various solutions from Stack Overflow, but I'm new to Bootstrap 4. The goal is to position the logo at the top center of the login form, hence why I want the form centered on the page.


    <style>

    .form-style-5{
      max-width: 500px;
      padding: 10px 20px;
      margin-top:2em;
      margin: 10px auto;
      margin-bottom: 1em;
      padding: 30px;
      background-color: #ffffff;
      border-radius: 8px;
      font-family: Georgia, "Times New Roman", Times, serif;
    }

    .container{
      margin-bottom: 2em;
    }
    </style>
</head>
<body style="background-color:rgb(20, 96, 131)">
      <div class="container" style="padding:50px">
    <form class="form-style-5" method="post">
      <h1 style="font-family:verdana" class="text-center">Sign up</h1>
        {% csrf_token %}
        <table>
        {{user_form | crispy}}
        {{details_form | crispy}}
        <button class="btn btn-primary btn-block fa-lg gradient-custom-2 mb-3" type="submit" style="background-color:rgb(20, 96, 131); border: 0px">Sign up</button>
    </form>
    <hr>
    <div class= "row">
      <div class="col-sm-6"><a href="/login" class="btn btn-primary btn-block fa-lg gradient-custom-2 mb-3" style="background-color:rgb(20, 96, 131); border: 0px">Login</a></div>
    <div class="col-sm-6"><a href="/seller_signup" class="btn btn-primary btn-block fa-lg gradient-custom-2 mb-3" style="background-color:rgb(20, 96, 131); border: 0px">Seller's Sign-up</a></div>
    </div>
  </table>
</div>
</body>
</html>

Answer №1

One way to center the entire form on the page is by placing it within a container specifically for positioning purposes and using viewport units for placement. This approach allows you to position the form without having to simultaneously format its container. Instead of using the container class with absolute positioning, you could opt for a less disruptive method. Feel free to adjust the values to align the form higher or lower on the page; for this example, I centered it.

.form-style-5 {
  max-width: 500px;
  padding: 10px 20px;
  margin-top: 2em;
  margin: 10px auto;
  margin-bottom: 1em;
  padding: 30px;
  background-color: #ffffff;
  border-radius: 8px;
  font-family: Georgia, "Times New Roman", Times, serif;
}

.container {
  margin-bottom: 2em;
}

.position {
  height: 100vh;
  width: 100vw;
  display: flex;
  justify-content: center;
  align-items: center;
}
<html>

<body style="background-color:rgb(20, 96, 131)">
  <div class="position">
    <div class="container" style="padding:50px">
      <form class="form-style-5" method="post">
        <h1 style="font-family:verdana" class="text-center">Sign up</h1>
        {% csrf_token %}
        <table>
          {{user_form | crispy}} {{details_form | crispy}}
          <button class="btn btn-primary btn-block fa-lg gradient-custom-2 mb-3" type="submit" style="background-color:rgb(20, 96, 131); border: 0px">Sign up</button>
        </table>
        <hr>
        <div class="row">
          <div class="col-sm-6"><a href="/login" class="btn btn-primary btn-block fa-lg gradient-custom-2 mb-3" style="background-color:rgb(20, 96, 131); border: 0px">Login</a></div>
          <div class="col-sm-6"><a href="/seller_signup" class="btn btn-primary btn-block fa-lg gradient-custom-2 mb-3" style="background-color:rgb(20, 96, 131); border: 0px">Seller's Sign-up</a></div>
        </div>
      </form>
    </div>
  </div>
</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

Customize Your ERPNext Website: Displaying a specific type of Blog Posts

Is there a way to display only a specific category of Blog Posts in a Webpage Section created using the Page Builder? I have designed a Web Template in EPRNext that showcases Blog posts on any webpage by adding a Section through the Page Builder. It' ...

Eliminate the content located between two specific words in the img src URL and then render the file from the new source by utilizing ht

My img tags have parameters in the url for ajax image crop functionality. Here's an example: <img src="/resize/45-800/files/myImage.jpeg" alt="Chania"> Add /resize/45-800/ before the url to instruct the ajax script to fetch the file from the f ...

The flex grow animation fails to activate when the Bootstrap 4 style sheet is added

Trying to implement transitions with flex grow has been a challenge. It works smoothly without any issues, but as soon as I add the bootstrap 4 style sheet, the transitions stop working. I haven't even started using the bootstrap 4 classes yet, it&apo ...

Theme.breakpoints.down not being acknowledged by MUI breakpoints

The Challenge: Implement a hamburger menu to replace the navMenu on tablet and smaller screens After successfully compiling in VS code terminal, encountering an error in the browser: Error Message: TypeError: Cannot read properties of undefined (reading ...

Error in jQuery submenu positioning issue

I am attempting to design a menu that opens when the parent element is clicked and closes when the mouse leaves the previously opened one. It should operate from left to right. Here is an example: <ul class="menuFirst"> <li><im ...

The boundary of embedded components

I am looking for CSS code that will allow me to arrange all elements with specific indents, such as placing the first element on the left side of the page, followed by an image with some indentation, and so on. <div class="container-fluid"> &l ...

Prevent the colorpicker feature for the <input type="color"> element on Google Chrome

When using Google Chrome, the <input type="color"> element creates an input field with a color bar inside it. By default, it opens a colorpicker that may vary in appearance depending on the operating system (mine has a Windows theme). I have implemen ...

Switching the menu in mobile view: utilizing vue and pug

Hello, I am having trouble toggling my hamburger menu. When I check the console, it shows an error message: "nav is not defined". header.pug header.site-header div.navbar div.navbar__link.navbar--brand logo div.navbar ...

The issue of HTML5 audio not working when played multiple times on an Android 4.0.4 device's Native Browser

Currently engaged in a project utilizing HTML5 technology. Encountering an issue with playing the same audio file multiple times on the same page using the Android native browser. The problem is specifically observed on Android ICS 4.0.4. In this version, ...

Viewing the information stored in a text file hosted on a web server

I need help enhancing the functionality of a webpage on my server. Specifically, I want to display the contents of a text file saved on the server. I am struggling with the syntax, but it seems to involve using Flask along with HTML and JavaScript function ...

How can I retrieve the position of a div or an image within a div (specifically the top and left coordinates) and incorporate these values into CSS?

I'm currently working on a website that is dynamic and utilizes bootstrap. I am looking to incorporate an animation where the dynamic thumbnails in the col-md-4 div zoom to 100% when clicked, appearing at the center of the container. I am struggling ...

Understanding the differences between jquery's addClass method and the .css()

After creating a function to set a background on a click event, I encountered an issue. I attempted two different methods, expecting both to be successful. However, only the .css() version worked while the addClass method failed. Why is this happening? fu ...

Creating an automated HTML tag for a form input

https://i.sstatic.net/ZBDk2.png Is there a plugin to create form inputs like the one shown above? How can I add this feature to my own website? I would like for every user input to automatically add the < br > tag. ...

How can I dynamically alter the width of a Bootstrap progress bar using the {{$percentage}} variable in a Laravel stylesheet?

I am currently working on a project where I aim to display the percentage of marks obtained using a progress bar. I have the percentage value and I am trying to pass this value in the style: "width:{{$percentage}}" so that the progress bar width changes a ...

How can one guide a glTF model in the direction it is pointed using A-frame?

I have a 3D model of my customized robot loaded in an A-frame scene using version 1.0.4. Currently, I am able to rotate the robot along its x, y, z axes, but I am facing an issue where it continues to move in its original direction rather than the one it i ...

What is the best way to modify the inline style width of a table td from pixels to percentage in order to make it

<table> <tr style="height:15pt;"> <td style="width:229pt;border-style:solid;border-width:0pt;padding:3pt 9pt 3pt 0pt;" valign="bottom" bgcolor="#c0c0c0"><p style="font-family:Times New Roman, serif;font-size:10pt;font-style:norm ...

I possess 9 captivating visuals that gracefully unveil their larger counterparts upon being clicked. Curiously, this enchanting feature seems to encounter a perplexing issue within the realm of web browsing

<style type="text/javascript" src="jquery-1.11.0.min.js"></style> <style type="text/javascript" src="myCode.js"></style> </body> //jquery is within my site directory on my desktop $(document).ready(function(){ //note: $("#ar ...

What is the process of sending emails in PHP?

Seeking guidance on how to send mail through PHP with attached objects. As a newcomer, I would appreciate any assistance in this matter. Is there a specific server that needs to be installed? The email should be able to be sent from any email account. Ca ...

Is it necessary to upload static files in included HTML when using Django?

I am currently in DEBUG mode and I need to convert an HTML page into a PDF using PrinceXML. Within my main HTML file, the code looks like this: {% extends "base.html" %} {% load staticfiles %} {% load url from future %} {% block title %}Title{% endblock ...

Is there a discrepancy in height between Chrome's mobile emulator and the iPhone simulator?

Currently, I am conducting a layout test for a PhoneGap application using the Framework7 framework across the Chrome mobile emulator (iPhone 6) and Xcode iOS simulator. However, I am facing difficulties with aligning the vertical layout on both simulators. ...