Aligning form elements vertically in the center using Bootstrap 4

I am struggling to center the content of my entire page both horizontally and vertically. Despite following the guide on Bootstrap 4 beta's official website, I can't seem to get it right - https://getbootstrap.com/docs/4.0/layout/grid/

    html, body {
    height: 100%;
    }

    .bg-color {
        width: 100%;
        height: auto;
        min-height: 100% !important;
        background: #4e4376;  
        background: -webkit-linear-gradient(to bottom, #2b5876, #4e4376);  
        background: linear-gradient(to bottom, #2b5876, #4e4376);
        
    }
    body::after {
        content: "";
        background-image: url("assets/group.jpg");
        opacity: 0.1;
        top: 0;
        left: 0;
        bottom: 0;
        right: 0;
        position: absolute;
        z-index: -1;  
        background-position: center;
        background-repeat: no-repeat;
        background-size: cover; 
    }
    <div class="container-fluid">
        <div class="row justify-content-center align-self-center">
            <div class="col col-sm-6 col-md-6 col-lg-4 col-xl-3 h-100">
                <form action="">
                <div class="form-group">
                    <input _ngcontent-c0="" class="form-control form-control-lg" placeholder="User email" type="text">
                </div>
                <div class="form-group">
                    <input class="form-control form-control-lg" placeholder="Password" type="password">
                </div>
                <div class="form-group">
                    <button class="btn btn-info btn-lg btn-block">Sign In</button>
                </div>
              </form>
          </div>
      </div>
  </div>

Could someone assist me in resolving this issue? Thank you

To provide a better visual representation of what I'm looking for: https://i.sstatic.net/lwnE2.png

Answer №1

Don't forget to integrate bootstrap into your web development project. Take note of the initial line in the HTML code.

html, body {
    height: 100%;
    }

    .bg-color {
        width: 100%;
        height: auto;
        min-height: 100% !important;
        background: #4e4376;  
        background: -webkit-linear-gradient(to bottom, #2b5876, #4e4376);  
        background: linear-gradient(to bottom, #2b5876, #4e4376);
        
    }
    body::after {
        content: "";
        background-image: url("assets/group.jpg");
        opacity: 0.1;
        top: 0;
        left: 0;
        bottom: 0;
        right: 0;
        position: absolute;
        z-index: -1;  
        background-position: center;
        background-repeat: no-repeat;
        background-size: cover; 
    }
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<div class="container-fluid">
        <div class="row justify-content-center align-self-center">
            <div class="col col-sm-6 col-md-6 col-lg-4 col-xl-3 h-100">
                <form action="">
                <div class="form-group">
                    <input _ngcontent-c0="" class="form-control form-control-lg" placeholder="User email" type="text">
                </div>
                <div class="form-group">
                    <input class="form-control form-control-lg" placeholder="Password" type="password">
                </div>
                <div class="form-group">
                    <button class="btn btn-info btn-lg btn-block">Sign In</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

Changing the CSS attributes of a DIV element while inside a complexly nested IFRAME

Currently, I am dealing with a business intelligence tool that restricts me to working within a deeply nested iframe in order to add code. My goal is to leverage jQuery and/or JavaScript to adjust the left and position CSS of a div located three iframes ab ...

Is there a way to identify the specific cell I've modified using bootstrap dataTables?

Working with editable bootstrap datatables, I am looking to update the mySQL database when a cell is edited: index.php: <!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/css" href="http://cdn.datatables.net/1.10.11/ ...

`Execute onClick function for submit button only when all the required input fields have been populated`

I have created a form with mandatory fields and included an onClick event listener on the submit button to show a loading spinner while the process is running. However, I am facing an issue where the onClick function is triggered every time the button is c ...

Transforming Plain Text to HTML Format

Currently, I am fetching some Strings from a database and successfully converting them to HTML using the following code: private string StripHTML(string source) { try { string result; // Code for stripping ...

The issue with the angular2 bootstrap4 tooltip is that it cannot render HTML, whereas the popover feature is capable

Currently, I am utilizing angular2 along with bootstrap4. The Popover feature is able to properly display raw HTML content as bold text asdf <img src="assets/images/1.jpg" data-container="body" data-toggle="popover" data-ht ...

Saving a PHP form with multiple entries automatically and storing it in a mysqli database using Ajax

My form includes multiple tabs, each containing various items such as textboxes, radio buttons, and drop-down boxes. I need to save the content either after 15 seconds of idle time or when the user clicks on the submit button. All tab content will be saved ...

The max-width attribute is failing to apply to the form within the Bootstrap framework

login.html file: {% extends "base.html" %} {% block content %} <div class="container login-page-form"> <form id="login-form" action="/auth/login" method="post"> <div class="f ...

Is there a way to use a single url in Angular for all routing purposes

My app's main page is accessed through this url: http://localhost:4200/ Every time the user clicks on a next button, a new screen is loaded with a different url pattern, examples of which are shown below: http://localhost:4200/screen/static/text/1/0 ...

Setting up Bootstrap in Visual Studio for a seamless integration

Currently, I am working with the most recent version of VisualStudio which includes an older version of Bootstrap 3 when selecting the application template. I attempted to manually transfer the library files from the updated Bootstrap 4 to the root folde ...

After installation, the Tailwind classes seem to be malfunctioning

Let me start by mentioning that although the title of this question is reminiscent of this other question on Stack Overflow, I have already tried the solutions provided there with no success. I initially attempted to set up Tailwind using their official C ...

When the browser window is resized, the footer starts to cover the content

To prevent the divs from overlapping when the browser window is resized vertically, take a look at the code snippet below: <html> <body> <style> #box { display: flex; flex-direction ...

A guide on how to use Bootstrap to align elements at the center of a div container

My attempt to center an image in the div didn't quite work out as planned. Here's the snippet of my html and css: .col-xs-4 { background-color: lightgrey; width: 300px; height: 200px; border: 6px solid green; padding: 25px; margin: ...

What is the best way to horizontally align text in a container without it remaining at the top?

My attempts to center the button using vertical-align: middle and text-align: center have been unsuccessful, as the styling does not affect the button's position and it remains at the top. I am puzzled by why the style is not being applied. While I c ...

Requirement needed for the modal bootstrap to appear

Is there a way to prevent the modal from displaying and instead show another modal requiring me to fill in the "origin" or "destination" input fields if they are left blank when clicking the "Book" button? Currently, even if the inputs are empty, it stil ...

Even when the dimensions are set to 100 width and height, the scroll bar still makes an

I recently embarked on my journey to learn web development by enrolling in a course on Udemy. Currently, I am diving into CSS3/HTML5 and have started a small project involving CSS3 - creating a web page that represents the Universe. My goal is to incorpora ...

Creating a Dynamic Bar in Your Shiny Application: A Step-by-Step Guide

Currently, I am developing a unique crowd funding shiny app to monitor donation amounts. Is there a method available that allows for the creation of a reactive bar in Shiny? Alternatively, is it feasible to achieve this using html, css, and javascript? He ...

Exploring the Features of Bottom and Right in jQuery

Here is a snippet of jQuery code that I included in a sample program: $('#left').click(function(){ $('.box').animate({ left: "-=40px", }, function(){/* End of Animation*/}); }); $('#right ...

Having trouble getting the <script> tag to function properly in HTML <head> or an external JS file

Attempting to include js in an HTML file. Imported the external js files using the script tags below <script type="text/javascript" src="scripts/ui.js"></script> <script type="text/javascript" src="scripts/events.js"></script> Unf ...

Broken styles when using Material UI with babel and the 'with styles' feature

We've implemented babel and lerna to maintain specific elements of our react web app separately. While the setup has been effective thus far, we're encountering styling issues when generating the static build. The main project is not processed t ...

The interaction between jQuery Masonry and Bootstrap results in unexpected grid behavior

I've spent hours trying to solve this problem, but I can't seem to get it to work as intended. I want the layout of my boxes to be like this using Bootstrap grids: However, after implementing the jQuery Masonry plugin (which I used to manage va ...