Seeking assistance with creating a form that is centered on the page

As a newcomer here, I am in the process of learning new things. My current challenge is to create a center form.

Here is what I have experimented with so far:

<!doctype html>
<html lang="en>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Bootstrap demo</title>
  <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dfbdb0b0abacabadbeaf9feaf1edf1eff2bdbaabbeee">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">

  <style>
    .container {
      height: 100%;
      width: 50%;
    }
    
    .center-block {
      margin: auto;
      display: block;
    }
  </style>

</head>

<body>
  <div class="container">
    <h1 class="text-center fst-italic mt-5">CARD NUMBER CHECKER</h1>
    <br>
    <br>


    <div class="inpCont ">
      <div class="row g-3 align-items-center">
        <div class="col-auto">
          <label class="col-form-label text-center">Input Number</label>
        </div>
        <div class="col-auto">
          <input type="text" class="form-control text-center">
        </div>
      </div>
    </div>
    <br>
    <div class="d-grid gap-2 col-3 mx-auto">
      <button class="btn btn-warning" type="button">Submit</button>
    </div>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="95f7fafae1e6e1e7f4e5d5a0bba7bba5b8f7f0e1f4a4">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2" crossorigin="anonymous"></script>
</body>

</html>

As of now, this is the appearance that I am achieving with the code above: https://i.sstatic.net/G2A4c.png

I aim to achieve the exact layout shown in the image below:

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

Any assistance in centering the input box as depicted in the image would be greatly appreciated :)

Answer №1

Instead of adding extra CSS, Bootstrap 5 provides classes that can handle all of those tasks for you:

https://getbootstrap.com/docs/5.0/utilities/flex/

https://getbootstrap.com/docs/5.0/utilities/spacing/

d-flex makes the container div a flexbox, flex-column changes the direction to a column, align-items-center centers everything horizontally, and gap-4 creates spacing between elements. You may even eliminate the input container if not needed for anything else.

h1 {
  font-family: Georgia, "Times New Roman", Times, serif;
}
<!doctype html>
<html lang="en>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Bootstrap demo</title>
  <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b0d2dfdfc4c3c4c2d1c0f0859e829e809dd2d5c4d181">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
</head>

<body>
  <div class="d-flex flex-column align-items-center gap-4">
    <h1 class="text-center mt-5">CARD NUMBER CHECKER</h1>
    <div class="row g-3 align-items-center">
      <div class="col-auto">
        <label class="col-form-label text-center">Input Number</label>
      </div>
      <div class="col-auto">
        <input type="text" class="form-control text-center">
      </div>
    </div>
    <div class="d-grid gap-2 col-3 mx-auto">
      <button class="btn btn-warning" type="button">Submit</button>
    </div>
  </div>
</body>

</html>

Answer №2

this code snippet will help to center the content on the page

.inpCont {
    display: flex;
    justify-content: center;
}

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

Currently, I am in the process of constructing a DSpace repository on an Ubuntu 16.04

I have successfully set up a DSpace repository on Ubuntu 16.04 LTS by following the installation instructions provided in this manual. After deploying the webapps, I encountered an issue when trying to add new items. Upon clicking the search link, I recei ...

JQuery Load fails to load in real-time

I have a PHP file where I am using JQuery to load the content of another file called 'live.php' which should display the current time, but for some reason it is not loading live. Can anyone help me troubleshoot this issue? It used to work perfect ...

Bootstrap 4 Carousel: Displaying Multiple Frames Simultaneously and Sliding One at a Time

A different query was raised regarding the same issue (refer to the mentioned question) for Bootstrap 3, however, the suggested solutions are not compatible with Bootstrap 4. The illustration in this post effectively conveys what I am aiming for. Take a ...

Issues with Google Chrome truncating the end of lengthy pages

While working on a website project, I encountered an issue with Chrome where loading a lengthy page results in a strange box covering the bottom portion of the content. Interestingly, the same pages appear fine on Safari and Firefox, indicating that the pr ...

Increase the distance between input boxes using CSS styling

I'm encountering an issue with adding spacing between input boxes, despite attempting to use padding. The padding only seems to move the boxes instead of creating space between them. Here is my code: ...

utilizing AJAX to send a POST request and display the response in HTML using Django

I am looking to input a number into a text box and retrieve all the even numbers using ajax with Django. Here is my view: load_template @csrf_exempt def load_template(request): if request.method == 'POST': num1 = request.POST[&a ...

Display input field in AngularJS when radio button is selected

My JavaScript array looks like this: $scope.quantityMachines = [ { 'snippet' : 'One' }, { 'snippet' : 'Two' }, { 'snippet' : 'Three or more', 'extraField' : true }, { ' ...

Is it advisable to blend Angular Material with Bootstrap?

I'm brand new to Angular Material and it seems to have its own intricate API. Coming from using Bootstrap, I'm accustomed to utilizing its grid system with classes like row, containers, cols, etc. I'm curious if it's considered a good o ...

How can I ensure that my SVG Image perfectly fits within the Parent wrapper div?

I've been grappling with the following code snippet. I'm struggling to make my SVG image fit within my container div. .img { margin: 0; padding: 0; overflow: hidden; width: 500px; position: relative; } img { top:0; ...

Tips for restricting navbar-fixed to the width of the container

Welcome to my first project utilizing Twitter Bootstrap. While using Twitter Bootstrap, I've noticed that whether I use container-fluid or just container for my fixed top navbar, it expands to full width of the browser once it reaches around 980px. T ...

Modifying the background hue of the element-ui tooltip

I am currently working with vue.js version 2.6.10 and element-ui version 2.15.1. The element-ui component I am using is as follows: <el-tooltip content="Top center" placement="top"> <span>Dark</span> ...

Modifying Margin and Spacing for Selections in Radio Buttons

I have successfully implemented the code for a radio button, and everything is working as expected div > label { margin-right: 80px !important; box-shadow: .3rem .3rem .6rem #c8d0e7, -.2rem -.2rem .5rem #FFFFFF; position: relative; ...

Is it possible to adjust the maximum time limit for uploaded video files in Vue?

I'm facing an issue while trying to dynamically change the maximum value of a time input field in Vue JavaScript after uploading a video file. Despite setting the attribute `max` on the input element using JavaScript, I am unable to update the max val ...

Issue with Angular 6: Jquery unable to detect element when using *ngIf directive

I'm currently developing an app using Angular 6, and I am facing an issue while trying to add a class using the jquery hover() method. In my navigation menu, I have 5 links, and although they all appear the same, 2 of them have an added *ngIf directiv ...

An alternative method to confirm the checkbox selection without physically clicking on it

Currently, I'm in the process of creating a basic to-do list and have been attempting to connect the task with its corresponding checkbox. My goal is for the checkbox to automatically be checked when the task is clicked. Instead of using HTML to add ...

Acquire Table Element Using Javascript

I have a HTML table that contains information such as names, addresses, and phone numbers. Within each row of the table, there is a link that can be clicked to open a popover. When a popover is opened, I want to save the name from that particular row. The ...

Ensure equal width for an HTML element by matching it with the dimensions

Hello, I am facing an issue with a dropdown button. Whenever I hover over it, the links to different pages drop down. However, I want the width of these links to be the same as that of the button. The size of the button varies as it is set to 100% width o ...

Enhancing Bootstrap project with personalized CSS styling

Utilizing SCSS to create my CSS has been the approach I've taken. The content of my main.scss file remains consistent even after it is compiled into css. .my-custom-row { background-color: bisque; } Contained within my index.html file is everythi ...

Fading effect of Bootstrap JS on reducing content size

My quest for a toggle collapse button led me to this helpful link: https://getbootstrap.com/docs/4.0/components/collapse/ I found what I needed, but encountered an issue with the transition; clicking on the button immediately reveals my div. I desire a slo ...

PrimeFaces: Achieving Conditional Coloring Based on Status (Passed/Failed)

Attempting to dynamically change the color of a column based on its status value (Passed/Failed/InProgress) using jQuery. I tried copying and pasting the table into jsfiddle, where it worked. However, when implemented in the actual XHTML file, the jQuery ...