Bootstrap CSS flexibly decreases the size of the input field on the form

I'm having trouble with Bootstrap-5. When I add the d-flex class to a container, my form inputs and labels shrink. If I remove d-flex, justify-center, and align-items-center from the container class, the form is no longer centered on the page. Adding these classes back in centers the content but causes the form inputs to shrink. Thank you for any help!

<div class="container d-flex justify-content-center align-items-center min-vh-100"></div>
    <form method="POST" action="#">
        <div class="row">
            <div class="col-6 mb-3">
                <label class="form-label" for="item">Enter Item</label>

                <input class="form-control" id="item" name="item" required type="text" value="">

            </div>
        </div>
        <div class="row">
            <div class="col-6 mb-3">
                <label class="form-label" for="category">Category</label>

                <input class="form-control" id="category" name="category" required type="text" value="">

            </div>
        </div>
        <div class="row">
            <div class="col-6 mb-3">
                <label class="form-label" for="price">Price</label>

                <input class="form-control" id="price" name="price" required type="text" value="">

            </div>
        </div>
        <div class="row">
            <div class="col-6 mb-3">
                <label class="form-label" for="location">Purchase Location</label>

                <input class="form-control" id="location" name="location" required type="text" value="">

            </div>
        </div>
        <div class="row">
            <div class="mb-3 justify-content-around">
                <input class="btn btn-outline-success" id="submit" name="submit" type="submit" value="Enter Data">
            </div>
        </div>
    </form>
</div>

Before adding flex: https://i.sstatic.net/bcIG3.png

After adding flex: https://i.sstatic.net/EDCkR.png

Answer №1

Rework your HTML structure to resemble the following, adjust the col-6 classes as needed to increase width.

<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b5d7dadac1c6c1c7d4c5f5809b859b84">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" />
<div class="container d-flex justify-content-center align-items-center min-vh-100">
  <form method="POST" action="#" class="w-100">
    <div class="align-items-center flex-column row">
      <div class="col-6 mb-3">
        <label class="form-label" for="item">Enter Item</label>

        <input class="form-control" id="item" name="item" required type="text" value="">

      </div>
      <div class="col-6 mb-3">
        <label class="form-label" for="category">Category</label>

        <input class="form-control" id="category" name="category" required type="text" value="">

      </div>
      <div class="col-6 mb-3">
        <label class="form-label" for="price">Price</label>

        <input class="form-control" id="price" name="price" required type="text" value="">

      </div>
      <div class="col-6 mb-3">
        <label class="form-label" for="location">Purchase Location</label>

        <input class="form-control" id="location" name="location" required type="text" value="">

      </div>
      <div class="col-6 d-flex justify-content-center mb-3">
        <input class="btn btn-outline-success" id="submit" name="submit" type="submit" value="Enter Data">
      </div>
    </div>
  </form>
</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

When the width of a single table is large, Bootstrap tables can appear misaligned and not properly

I am facing an issue with displaying two tables side by side. Whenever the width of the first table is too large, the second table is pushed below it. https://i.sstatic.net/w8zwp.png https://i.sstatic.net/SZdZU.png Is there a way to make them stay side b ...

Employing Bootstrap, incorporate a vertical divider in the center to split three icons on the left and three icons on the right, all while ensuring the design remains responsive

I have been struggling with a layout issue for the past couple of days and I am in need of assistance from someone who can help me. Unfortunately, I am unable to upload an image here as I am new and do not yet have enough reputation points. The Layout Str ...

Is there a way for me to have a background image behave like an img element with img-fluid class as shown in the

Showing 2 rows The issue lies with the first row, as it is not displaying properly and does not resize responsively like the second row. I have tried everything but nothing seems to work. I am attempting to do this because the text and elements in the ...

Adjust the svg rate using jQuery or JavaScript

Seeking help with a gauge I found on CodePen - struggling to adjust bubble values... <path id="Fill-13" fill="#F8B50F" d="M3.7 88.532h26.535v-#.795H3.7z"/> Can change the bars in JS, but not the bubbles using jq/js. Adjust the gauge with values be ...

jquery is in motion while svg paths are at a standstill, waiting to

i have been attempting to incorporate a css-animated svg into my project. initially, the animation would start automatically, which was undesirable. after some research, i discovered that by declaring it as paused and then triggering it using jQuery with $ ...

Eliminate unnecessary scrollbar from fancybox iframe

I am trying to display content in an iframe using Fancybox, but I am encountering an issue. Despite all the content being contained within the iframe, horizontal and vertical scroll bars are appearing. When inspecting the element in Firefox, I noticed th ...

What is the best way to apply maximum height to an element using CSS?

Looking for help with my website: I made some changes in the code using Firebug and identified these elements that I want to modify (but changes are not live yet) The following code represents the elements on my site: This is the HTML code: <di ...

Can MUI 5 replicate the Emotions 'css' function through analog?

From what I've learned, MUI 5 utilizes Emotion for its styling framework. Emotion offers a convenient helper function called css, which generates a string - a class name that can be used as a value for the className property or any other relevant prop ...

Transforming brand logos through hover on image maps

Despite finding numerous posts addressing this issue, I am still encountering problems with my code: <div id="product_tabs_description_tabbed_contents" style="display: block;"><img style="margin-left: -10px; opacity: 1 !important;" src="{{media u ...

Hovering over graphics for automatic scrolling

I have successfully implemented a hover effect that scrolls down an image inside a div. However, I am facing an issue with making the scroll longer for images of varying lengths by using calc inside the transition property. Below is the code snippet that ...

Repairing the Left-sided Popup Leaflet

Can someone help me with fixing the positioning of the Popup to the left of the map? Currently, it does not stay aligned to the left edge when moving the map. I tried using position: fixed in my styling, and while everything looks good when zooming, it br ...

What is the best way to assign the order position in CSS?

I recently attempted to incorporate a CSS animated background into my project. Here is how it currently looks: The particle effect hovers above the menu list (which currently just says "test"). The CSS code for my particles is as follows: .circles { pos ...

How can you handle all HTML tags with Regex in a single line of code?

I've developed a PHP script that converts all inline CSS in HTML tags to classes. Visit the following link for more information: https://gist.github.com/iBars/aa52c6119e53908c91ac553aeba229e0 However, it currently only processes tags that are the onl ...

:after functionality not operating properly in Internet Explorer

The titles on this page have arrows displayed before them using a special styling. However, there seems to be an issue with how it displays on Internet Explorer. // edit : I made a mistake, my styling is actually on paragraph tags 'p'. Maybe tha ...

Tips for enabling the wrap property with autogeneratecolumn set to true

In my grid view, I want to ensure that any text in a column that exceeds the width of the column will either wrap within the column or display on a new line. Below is the code for the grid view: <asp:GridView ID="GridView1" AllowSorting="True" runa ...

Troubleshooting problem: Scrolling problem in IE7 and IE8 with Lightbox

The lightbox I'm using works flawlessly on all browsers, except for IE. When viewed on IE, it shows triple scroll bars. Here is the CSS code for the iframe: #wrap { float:left; width:800px; height:500px; overflow-x: hidden; overflow-y: scroll; } #co ...

Is there a way to adjust the transparency of specific text when clicking on a different div?

How can I display a line of text when the "Contact Us" button is clicked on a practice website, similar to this: https://i.sstatic.net/MgbYQ.png I have set the current opacity of the submit message to 0 so it is hidden, but is there a way to change its o ...

Is there a way to clear a @font-face downloaded font from the browser cache?

Recently, I realized that I made an error in my webapp release by using a limited version of "Droid Sans" with @font-face for Latin characters. The font files are hosted on my server. To rectify this issue, I have now updated the font to the full version s ...

How to dynamically add table rows and cells with JavaScript using a single selection input

I am working on a project that involves a selection input with around 5 options. Additionally, there is an empty table that follows this format: <table> <tr> <td>X (for deletion)</td> <td>Option name</td> ...

Utilizing iPad, Safari, and CSS to effortlessly fill a page with flexbox properties

Trying to create a flex layout that expands the main area to fill the entire height of the display, with a footer always at the bottom when the content is small. However, if the main content exceeds the display size, it should behave like a normal page and ...