My Bootstrap/Flexbox layout is not behaving as anticipated. Can anyone identify any issues in my code?

I'm currently working on a MVC website that features a login/signup form. I have been trying to utilize bootstrap to format the forms. My main goal is to center the entire form on the screen, but so far I have only been successful in centering it on the horizontal axis. I have experimented with various options such as 'justify-content-center', 'align-items-center', 'align-self-center', and 'align-content-center', but none of them have had the desired effect on the layout of my page.

Below is the code I have been working with:

<div class="d-flex justify-content-center">
  <div class="login-card">
      <h2 class="page-title">Signup</h2>
      <form class="form signup-form">
        <div class="form-group">
          <label for="username-signup">Username:</label>
          <input class="form-input" type="text" id="username-signup" />
        </div>
        <div class="form-group">
          <label for="email-signup">Email:</label>
          <input class="form-input" type="text" id="email-signup" />
        </div>
        <div class="form-group">
          <label for="password-signup">Password:</label>
          <input class="form-input" type="password" id="password-signup" />
        </div>
        <div class="form-group">
          <button class="btn btn-primary" type="submit">signup</button>
        </div>
      </form>
    </div>
  </div>
</div>

Answer â„–1

To ensure that content is vertically centered in the viewport, it is important to set the minimum height of the content to 100% of the viewport height. The default height of the content is the actual rendered height of the content.

The recommended Bootstrap class for this purpose is min-vh-100, which applies the style min-height:100vh!important. This will allow you to vertically center the content using the class align-items-center.

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

<div class="d-flex justify-content-center align-items-center min-vh-100">
  <div class="login-card">
      <h2 class="page-title">Signup</h2>
      <form class="form signup-form">
        <div class="form-group">
          <label for="username-signup">Username:</label>
          <input class="form-input" type="text" id="username-signup">
        </div>
        <div class="form-group">
          <label for="email-signup">Email:</label>
          <input class="form-input" type="text" id="email-signup">
        </div>
        <div class="form-group">
          <label for="password-signup">Password:</label>
          <input class="form-input" type="password" id="password-signup">
        </div>
        <div class="form-group">
          <button class="btn btn-primary" type="submit">signup</button>
        </div>
      </form>
    </div>
  </div>
</div>

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

Steer clear of altering line spacing in CSS

Here is the HTML structure that I am working with: <div id="id1"> <h1>my name </h1><h3><a href="mailto:myemail_id"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ff92869a929e9693969bbf878685d19 ...

React - method for transmitting dynamically generated styles to a div element

As a newcomer to the world of React, I keep encountering an unexpected token error related to the ":". Can someone please assist me with understanding the correct syntax for including multiple styles within the Box component provided below? Additionally, h ...

Ensure that the display is set to block to stack the input elements on top of each other

I am attempting to grasp the functionality of CSS display property and experimented with this basic HTML code: <div> <form className="container" action=""> <input name="fName" placeholder="First Name" type="text" value={props.fNam ...

Having issues with jQuery's .hover and .mouseleave functions causing unintentional looping. Any suggestions on how to resolve this

What I want to achieve: When hovering over the image, it fades out. Text should fade in after the image fades out. Text should fade out when the mouse leaves. The original image should fade back in. End with the original image and no text displayed. Iss ...

Implementing an onClick event to reveal a concealed div located above each bar in D3.js (potentially requiring additional CSS code)

I'm currently working on a project where I want a hidden div, named myDiv, to be displayed above the clicked bar whenever a square bar is clicked. Here's what I've attempted so far: 1) I have written a Javascript function called showDiv() ...

Switching Font Family Option for Selection Mat in Angular Material

I'm currently working on changing the font of the options inside mat-select ("In what city were you born", etc). After some experimentation, I found that by setting ViewEncapsulation to none (allowing styles from other files to bleed in), I am able t ...

When the mouse hovers over the text inside a div, the link does not work in Internet Explorer

Here is some code for demonstration. I'm facing an issue where the link spans over the entire div, which works perfectly in Firefox. However, in IE, when I hover over the text, the cursor changes to a text cursor and the link doesn't work there. ...

What is the best way to showcase a ul element as inline-block?

Is there a way to keep the bottom menu aligned in one row on all screen sizes? I attempted using display: inline-block, but it doesn't seem to work for me. Below is the CSS code: footer #middle-footer { background: #F6F6F6; color: #000; font-size ...

"Efficiently Triggering Multiple Events with One Click in JavaScript

Hey everyone, I could use some assistance. I'm trying to execute multiple events with a single click. Currently, I can change the image in my gallery on click, but I also want to add text labels corresponding to each image. Whenever I click on a diffe ...

I am looking to split an array into smaller subarrays, each containing 5 elements, and assign a distinct class to the elements within each subarray. How can I

I have a group of "n" "li" elements that I would like to split into "x" subsets using jQuery. Each subset should contain 5 "li" elements, and I also want to assign a different class to each subset. <ul> <li>text1</li> <li>text2&l ...

The width of each column in this dataset is variable and unknown

I need to organize a varying number of items into columns. The sizes of both the items and container are unknown, as well as how many columns will fit or what width they should be. I want the browser to arrange the items in as many columns as possible with ...

Ignoring CSS transitions by changing the width property in JavaScript’s element.style

When attempting to create a smooth progress bar animation by adjusting the width using document.querySelector('#mydiv').style.width = '20%', I noticed that the new width is updated instantly rather than transitioning smoothly. It seems ...

Having trouble selecting links in the navigation bar

Just getting started with HTML/CSS and designing a website with buttons. Got some buttons up and running perfectly fine. But now, I'm working on a navigation bar with anchors inside. The problem is that while I can see the anchors when I open the webs ...

Is it possible that the div's height is not being set to 0 pixels

<div style="height:0px;max-height:0px"> </div> It appears that setting the height of a div to 0 pixels is not having the desired effect. The div is still expanding to display its contents, so how can we stop this from occurring? ...

Troubleshooting jQuery masonry problem related to initial display and height settings

Within a div, there is a masonry container with the inline style property display:none. With several divs on the page, clicking their respective buttons during load causes them to switch like a slideshow. This disrupts masonry's ability to calculate t ...

Display a list with collapsed columns on an accordion format for a more compact view on smaller screens

My Bootstrap table setup looks like this: <table class="table table-striped"> <thead> <tr> <th>Date</th> <th>Name</th> <th>LastName</th> <th>Color</th> <th>Car</th> ...

footer extending beyond the previous div's boundaries

Struggling with frontend development and creating a layout in html, css3, and bootstrap 4? I've managed to incorporate a subtle animation in the background (https://codepen.io/mohaiman/pen/MQqMyo) but now facing issues with overlap when adding a foote ...

Open a new HTML page with jQuery with a click event trigger on an iframe element

Hello everyone, I have a simple question as I am still learning about Jquery. I am attempting to load another .html page whenever a figure element is clicked on this .html page. However, the script tag is not working as expected. Can someone please assist ...

Count the start and end rows of a table within the <tfoot> using pdfHTML/iText 7

Currently, I am working on a project where I am developing a document generator that utilizes pdfHTML 3.0.3 and iText 7.1.14. The document includes a table displaying 'items'. It's worth noting that these item rows will likely span across mu ...

Strategizing button placement for maximum profit expansion

I am attempting to design a budget board using Bootstrap 4. Here is what I have done so far, and I want the buttons to look like the image below. I'm clueless on how to achieve this.. Current Output: Desired Output: .btn-warning { border: 1px s ...