Guide to aligning inline-forms at the center using Bootstrap 4

Check out my HTML:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
    </head>
    <body>
        <center class="container" style="margin:auto; background-color:black;">
            <img src=test + "0" id=image style="width:900px; height:900px;"><br/>
            <form class="form-inline" style="text-align:center;background-color:red;">
                <label id="out">wait...</label>
                <select class="form-control" style="width:111px;" id="sel1">
                    <option>flags 1</option>
                    <option>flags 2</option>
                    <option>people 1</option>
                    <option>people 2</option>
                    <option>people 3</option>
                </select>
                <div class="btn-group">
                    <button class="btn btn-outline-success" type="button" onclick='clearInterval(player);document.getElementById("image").src = "counter.gif";setTimeout(function(){ start(); },5000)'>play</button>
                    <button class="btn btn-outline-danger" type="button" onclick='clearInterval(player);document.getElementById("result").innerHTML = new Date().getTime() - timestamp'>stop</button>
                </div>
                <input class="form-control" type="number" id="delay" style="width:80px;">ms</input>
                <label id='result'></label>
            </form>
        </center>
    </body>
</html>

Even though I've applied text-align:center to the form tag, it's not aligning as expected. What can I do to center my form on the page?

What could be causing my code to behave differently than anticipated?

Answer №1

Please Verify Immediately

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
    </head>
    <body>
        <center class="container" style="margin:auto; background-color:black;">
            <img src=test + "0" id=image style="width:900px; height:900px;"><br/>
            <form class="form-inline justify-content-center" style="text-align:center;background-color:red;">
                <label id="out">Please wait...</label>
                <select class="form-control" style="width:111px;" id="sel1">
                    <option>flags 1</option>
                    <option>flags 2</option>
                    <option>people 1</option>
                    <option>people 2</option>
                    <option>people 3</option>
                </select>
                <div class="btn-group">
                    <button class="btn btn-outline-success" type="button" onclick='clearInterval(player);document.getElementById("image").src = "counter.gif";setTimeout(function(){ start(); },5000)'>play</button>
                    <button class="btn btn-outline-danger" type="button" onclick='clearInterval(player);document.getElementById("result").innerHTML = new Date().getTime() - timestamp'>stop</button>
                </div>
                <input class="form-control" type="number" id="delay" style="width:80px;">ms</input>
                <label id='result'></label>
            </form>
        </center>
    </body>
</html>

Answer №2

Include justify-content: center; to achieve the desired result.

To learn more about flexbox, visit: Flexbox Guide

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

Error: Missing Required Parameter for PUT Request

I'm encountering an error while trying to execute a PUT request. { "error" : { "status" : 400, "message" : "Required parameter position_ms missing" } } I have consistently used the same format for all previous PUT requests, and everythi ...

Is there a way to get Axios to display CSS on the page?

While working on a Web Viewer project with axios for web scraping practice, I encountered an issue where the CSS wasn't loading properly. Here is the code snippet I used: console.log("Tribble-Webviewer is starting!") const express = requir ...

Unusual images emerge following certain elements in this unique gallery

Looking for some advice on my image gallery created using an ordered list. The issue I'm facing is that the images are not all the same size, causing the 4th and 7th images to disrupt the layout. I have come up with a solution by using: ...

What are some ways to make the search bar on my website smaller in both length and width?

I have a WordPress website with the ivory search plugin installed for the search functionality. You can check out my website at www.osdoc.in. I am looking to make the search bar shorter and narrower as it is currently causing the menu icons to encroach on ...

How to extract text from an HTML file using Bash programming

I have a script that navigates through my data directory and retrieves text from HTML files using the Lynx tool. However, when I view the text file generated by the script, it displays an error message: 410 GONE This doesn't exist any more. Try html ...

Email design tip: Ensure consistent line heights by adjusting code for Outlook.com to override any default settings. Use the following CSS code: ``

I've been trying to fix this problem for 22 hours now, but as a newcomer, I think it's time to hand it over to the pros. I've been attempting to get rid of the extra line height that Outlook.com adds to emails, but I haven't had any lu ...

What is the best method for properly inserting images into a Vue Carousel 3D slider?

I'm currently exploring the Vue Carousel 3D documentation and I am having trouble displaying a single image on each slide. Let me elaborate: I aim to create a slider similar to the one shown in the Controls Customized example in the documentation. Th ...

Updating the contents of a list with new additions and removals

Struggling with a simple issue that I just can't seem to find a solution for. My problem involves a list based on 5 checkboxes. abc.html <li id="DisplaySelection"> </li> {{form.Test1 }} //checkbox1 .... {{form.Test5 }} //checkbox5 ma ...

Modify the colors of the chartist fill and stroke using JavaScript

Struggling to dynamically set colors in a chartist graph using JavaScript. How can custom colors be applied through JS? The attempted method below is not successfully changing the color for the showArea in the chartist graph. <!doctype html> <htm ...

Using mobile devices for multipart forms: managing actions that appear upon selecting a file input

My website features a multipart form where users are required to upload images. <form method="POST" encType="multipart/form-data" action="/uploads" id="forminho"> <div className="btn btn-success" id="submitFileBtn"> Select Image ...

Changing base 64 into Mp3 audio format using PHP

I currently have an "audio" tag with a script (which is essentially a plugin) that receives and saves it as base64. This functionality is working properly. My goal now is to modify the script in order to send the base64 data to the server, convert it to m ...

Press on a circle to adjust its size to fit the section or division

Is it possible to make a circle expand and fill the section/div when clicked? I want the circle to fill the screen upon clicking, and then have some text appear in its place. Before posting this, I searched on the web and came across this jsfiddle link. ...

What is the best way to style HTML content with MathJax following its retrieval with jQuery.load?

I recently encountered an issue while using jQuery.load to load a new page. The content on the original page is being treated strangely in some way. Specifically, I have code on the original page that formats LaTeX commands with MathJax: <script type=" ...

What is the best way to display the answer on a webpage?

... index.html <body> <h1>Upload Test</h1> <!--<form method="post" enctype="multipart/form-data" action="/picture"> --> <form id="pictureForm" method=& ...

Prevent table headers from scrolling in Bootstrap Vue by following these steps

Just starting out with bootstrap vue and I've been using version 1.4 for my application. I've utilized b-table for displaying my data, but I'm encountering a problem where the table headers also scroll along with the content. I'd like t ...

Elevated Positioning of Footer in Bootstrap

Hello, thank you in advance for any help offered. The website in question can be accessed through this link: caulfield.co/test/ I am working on implementing a parallax footer reveal effect using Bootstrap 4. I am having difficulty adjusting the z-index of ...

What are the steps to resize a YouTube embedded video?

I am currently attempting to use a YouTube video as the background for breadcrumbs on my website. However, I am facing an issue with setting the video width to cover the full screen. The image below shows that the video is displayed in the center of the if ...

Can we find a solution to optimize "Crystal Reports" for mobile browsers and make it responsive?

I'm in the process of making my entire Asp.net application responsive for mobile browsers by utilizing Bootstrap. However, I've encountered a challenge with making Crystal Report responsive for mobile browsers. If anyone has any advice on how to ...

What is the best way to ensure that a sidebar occupies the entire height of our webpage?

Here is the current layout of my sidebar: https://i.sstatic.net/c1sy6.png I want it to always occupy full height, how can I achieve this? I've tried using height: 100%, but it doesn't seem to work. Here is my CSS code: #sidebar { /* Make s ...

Bespoke HTML helper dropdown selection box

Here's a snippet I have: @Html.DropDownList("consultations", Model.ConsultationsTruncated, new { @class = "form-control", @id = "consultations" }) The displayed texts are truncated: For instance string s = "Hello everybody" ==> Text ="Hel..." ...