Achieving a perfectly centered alignment of two divs in Bootstrap 5 can be accomplished by placing one div with an input field next to another div

I am trying to center an input and a button on the same line within a div in the middle of the page. Currently, as shown in the image, they are aligned to the left of the page and I want them to be centralized. https://i.sstatic.net/o3RLs.png

<div class="row g-6 text-center">
                        
        <div class="col-md-4">
          <input type="email" style="text-align:left" class="form-control pl-2 shadow-none">
        </div>

        <div class="col-auto">
          <button class="btn btn-block btn-dark" type="submit">SUBSCRIBE NOW!</button>
        </div>
    
</div>

Answer №1

To align the content in the center, simply add the justify-content-center class to the row div like so:

<div class="row g-6 text-center justify-content-center">
  <div class="col-md-4">
    <input
      type="email"
      style="text-align: left"
      class="form-control pl-2 shadow-none"
    />
  </div>

  <div class="col-auto">
    <button class="btn btn-block btn-dark" type="submit">
      SUBSCRIBE NOW!
    </button>
  </div>
</div>

Take a look at a demonstration here: https://stackblitz.com/edit/web-platform-drknr7?file=index.html

Note: While we come from diverse backgrounds and speak different languages, it would be great if you could post in English for everyone to engage in the discussion :)

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

Chrome Experiencing Issues with Nested Divs

Having an issue with nested divs in Chrome <div id="wrapper"> <div id="content"> </div> </div> The wrapper div acts as a bordered container, forming a box. In Safari and Firefox, the content sits inside this box consistentl ...

What is the best way to highlight and extract only the white-coded texts on VSCode to facilitate the process of translating webpages manually?

Currently, I'm engaged in a project where my task involves duplicating an entire website using HTTrack. However, I only need to copy the main page and web pages that are one link deep. Upon copying the website, my next challenge is to translate all of ...

Choosing a single item from multiple elements in React using React and typescript

In this particular project, React, TypeScript, and ant design have been utilized. Within a specific section of the project, only one box out of three options should be selected. Despite implementing useState and toggle functionalities, all boxes end up bei ...

``Considering the compatibility issues with position: absolute in Internet Explorer 8

Here's an example snippet of code in HTML: <form> <input type="file" id="iefile"> </form> <form> <input type="file" id="iefile"> </form> This is how it looks with some CSS styling: form{ position:rela ...

Implementing Interactive Buttons

As a newcomer to JScript, I have been attempting to dynamically add textboxes and select menus to a form. While I have managed to make them appear on the page, I am facing an issue with JQuery not functioning properly. Although the textboxes are visible on ...

What is the best way to horizontally scroll to a selected item within a scrollable div using React?

I'm working on a project that involves creating a horizontal scrollable list. The goal is to have the list automatically scroll to the selected item, centering it in the view. While attempting to implement this feature using React, I've encounte ...

Is there a way to prevent the text next to these FontAwesome icons from moving whenever the icon itself changes?

I am currently working on creating a unique custom checkmark using FontAwesome in my project. Below is the snippet of HTML and CSS style code that I am using: .check { font-size: 1.25rem; cursor: pointer; } .check-unselected { color: #4E44 ...

Forming a jQuery element using a lengthy HTML code

Having a large HTML string that consists of multiple child nodes. Wondering if there is a way to create a jQuery DOM object from this string? Attempted to use $(string) but it only gave back an array with separate nodes. Trying to get an element that I ...

An issue arises in CSS when the styling is not correctly implemented on the HTML elements

I am currently trying to recreate this code on my own page: https://codepen.io/Vlad3356/pen/PoReJVg Here is the code I have written so far: https://codepen.io/Vlad3356/pen/GRxdMPz I'm puzzled as to why, when I click on a star in my version of the co ...

Safari is not properly handling element IDs when used in conjunction with React

I am currently in the process of building a straightforward single-page website utilizing React. At the top of the page, there is a navigation bar that contains links to various sections of the site: <li><a href="/#about">About u ...

When the page is resized, the Font-Awesome icons shift position

/* icon sect*/ .social { margin-top: px; padding: 0; position: absolute; top: 60%; left: 50%; transform: translate(-50%,-50%); } .social li { list-style: none; float: left; margin: 0px; width: 60px; height: 10px; line-height: 60px; ...

Launch a Firebase app with a custom .com web address

Just starting out in the world of hosting. I have a project that involves: Front end: HTML, CSS, JQuery Back end: Firebase Currently, I am using Firebase to store user data on my website. My goal is to host the site as abc.com However, when I contacted ...

Increase or decrease the quantity of items by cloning with Jquery and dynamically changing the ID

Currently, I am working on a jQuery clone project where I need to dynamically add and delete rows. Despite searching extensively on Stack Overflow and Google, I only have a basic understanding of how jQuery clone works. Any suggestions would be greatly ap ...

HTML is appearing as unformatted text on the screen

I am utilizing deta for rendering cloud-based HTML content. Below is the code snippet in use: from deta import Deta from fastapi import FastAPI, Request, Response, Form, File, UploadFile from fastapi.templating import Jinja2Templates from fastapi.response ...

Applying a border-radius to the input button

When trying to set border-radius to 14px for the textarea, it shows a missing attribute name. <input id="txtDateRange" type="text" name="daterange" value="" style="width:80%; border-radius: 14px;" class="PrintHide" /> What is the correct way to do ...

Is there a way to ensure the website's menu bar remains on a single line?

I'm currently working on a website and running into an issue with the menu bar. Everything looks perfect, but on larger screens or Android devices, the "Contact Us" menu item sometimes jumps to a new line unexpectedly. If you visit the webpage and tr ...

Prevent fixed element from scrolling beyond a specific point

I'm working on a fixed sidebar that needs to scroll along with the main content and stop at a specific point when scrolling down, and vice versa when scrolling up. I've created a script that calculates the window height, current scroll position ...

Troubleshooting Django Templateview: Incorporating Bootstrap Popovers into HTML tables not functioning properly

https://i.stack.imgur.com/LXHJF.pngWhen loading this template, the HTML renders correctly and the table loads successfully. However, certain cells have special pop-over attributes that do not work after the HTML is loaded via an AJAX request on the same pa ...

Animating the background color of a div vertically from the center using CSS3 or jQuery

I am attempting to achieve a similar effect to the right navigation on the following website: Using jQuery to create the effect where the color expands from the center is what I am aiming for. However, since that particular site was built using Flash, I a ...

Is there a JavaScript toolkit specifically designed for animating mobile devices?

Currently in search of a JavaScript Library that is similar to impress.js, allowing me to create dynamic animations on text content that are compatible with iOS/Android. Although Hype by Tumult seems promising, I am not interested in an editor but rather ...