How can we use Bootstrap to design a form with 3 input fields on one row, evenly spaced and occupying half the page's width?

<div class="container">
      <div class="row">
        <form class="inline-form">
          <div class="inline-form">
            <input type="text" placeholder="Your name">
          </div>
          <div class="inline-form">
            <input type="text" placeholder="Email address">
          </div>
          <div class="inline-form">
            <input type="text" placeholder="Phone number">
          </div>
        </form>
      </div>
</div>

I am looking to create a layout with three form fields, all of them having the same width and evenly spaced on a row. The HTML code provided is within a div that has a class of .col-md-6, which should occupy half of the page's width.

Answer №1

Check out this updated code:

<div class="container">
      <div class="row">
        <form class="form-inline">
          <div class="form-control">
            <input type="text" placeholder="Your name">
          </div>
          <div class="form-control">
            <input type="text" placeholder="Email address">
          </div>
          <div class="form-control">
            <input type="text" placeholder="Phone number">
          </div>
        </form>
      </div>
</div>

In this version, I made the following adjustments:

  • Changed the form class from "inline-form" to "form-inline"
  • Updated the div class from "inline-form" to "form-control"

I referred to the BS4 documentation for guidance: link

If you want to include .col-md-6, you can add it as a DIV tag before the container tag, like this:

<div class="cold-md-6">
    <div class="container">
        <div class="row">

            <form class="form-inline">

                <div class="form-control">
                    <input type="text" placeholder="Your name">
                </div>
                <div class="form-control">
                    <input type="text" placeholder="Email address">
                </div>
                <div class="form-control">
                    <input type="text" placeholder="Phone number">
                </div>

            </form>
        </div>
    </div>
</div>

[EDIT] Based on your initial code, I made some improvements to achieve your desired outcome.

Changes include:

  • Ensuring the form encompasses all input fields
  • Removing the container from the form tag (avoid nesting containers)
  • Adding col-4 to each form component
  • Including col-12 for the textarea

Answer №2

To make the form display horizontally, you can change the class to "d-flex flex-row".

Alternatively, you can group the input elements within a div container:

<div class="container d-flex mx-auto">
      <div class=" row">
        <form class="form-group">
          <div class="d-flex flex-row mb-4">
            <div class="form-control mr-3">
              <input type="text" placeholder="Your name">
            </div>
            <div class="form-control mr-3">
              <input type="text" placeholder="Email address">
            </div>
            <div class="form-control mr-3">
              <input type="text" placeholder="Phone number">
            </div>
          </div>
          <textarea class="form-control"></textarea>
        </form>
      </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

How can I give an HTML form input button the appearance of glowing or lighting up like the default OS style?

Is it possible to make the <li><FORM><INPUT class="eButton" type="button" value="Ole"></FORM></li> class glow or light up to notify the user about something, while maintaining the default OS look on Linux, Mac, and Windows? F ...

Getting rid of the excess space at the bottom of a Bootstrap card - tips and tricks!

I encountered an issue while developing a blog app. The problem is that instead of resizing to fit the size of the card, the content is occupying the entire column space. https://i.sstatic.net/CGRig.png Here's the code snippet (Jinja2) {% extends &q ...

Maintain the color of a Bootstrap 4 dropdown link even when it is open by incorporating hover

Currently, I am utilizing bootstrap 4 to create a menu that includes dropdown items. The issue I am facing is that when hovering over a dropdown link, the background color changes and the dropdown opens. However, as soon as I move the mouse to select one o ...

Scrolling vertically using window.open functionality

I am trying to open a pop-up window using window.open. I would like the scrollbars to appear only if necessary. Unfortunately, in Safari, the scrollbars do not show up unless I include scrollbars=1 in the code. However, this also causes horizontal scrollb ...

Problem encountered with HTML table formatting

I am struggling to create a table in HTML Click here for image Here is the code I have tried: <table> <tr> <th class="blue" colspan="3">3</th> <th class="orange " rowspan="2">2</th> <th class="blu ...

Photo positioned on top of the form with Bootstrap 5

I am working on creating a responsive webpage using Bootstrap, where I need to display a large image above a form. To manage the size of the image, I have placed it inside a "peek-view" container which allows scrolling both horizontally and vertically to v ...

What is the best way to center two items within a border?

Here is the CSS code I wrote to center align my text with a bottom border: .arrow-down { width: 2rem; display: inline; position: absolute; top: -0.6rem; left: 50%; margin-left: -59px; background: $grey_200; z-index: 5; } .showless > se ...

The external hyperlink is not functional in Firefox and Chrome browsers, but it operates properly in Internet Explorer 9

For security reasons, it seems that embedding an external link for live scoring from itftennis.com on our website is blocked. If you try to click on the jsfiddle LIVE SCORING link, it will open a page with an error. However, if you click on the address ba ...

I created an image that can be clicked on, but unfortunately it only functions properly on the

I am currently working on creating an image that can be clicked to cycle through different images all within the same frame. While I have managed to get it to work, I am facing a limitation where it only responds to one click. count = 1; function myF ...

Reveal and conceal grid elements upon clicking embedded links

I'm attempting to toggle the visibility of div content upon clicking a link. I've tried using a similar approach as shown in http://jsfiddle.net/fXE9p/, but unfortunately it didn't work for me. <body> Clicking on a button should m ...

Get notified about the number of cells you've selected by simply dragging on a table

Is there a way to display the number of selected cells in a table when dragging with the mouse? I have a table set up, and I'd like to create an alert that shows how many cells are selected while dragging. Here is the link to my fiddle: http://jsfiddl ...

posting data and redirecting fails when using an ajax button

I am encountering an issue where I click a button on a page to navigate to another page with posted data, but it is redirecting without posting anything. Both $_POST and $_SESSION variables are empty. Below is my ajax function: function ajax4(Div_Submit, ...

Different ways to trigger code behind method with onclick excluding asp:button OnClick

I am working with asp.net and I have a form that already uses runat="server". I have added another form to the page and I need to run a method in the code behind on an onclick event. Since I already have one form on the page, I cannot use an asp:button wi ...

jQuery show/hide functionality allows you to toggle the visibility of elements

I am looking to create a toggle button that expands the menu-wrapper width and hides the sidebar when clicked. Here is the initial CSS styling: #my-wrapper { Width:500px; } #sidebar-wrapper { width:200px; } Upon clicking the button, the CSS will update ...

Increasing the height of nested Bootstrap columns by stretching them out

I am trying to ensure that the first two columns in both the green and violet rows always have the same height. I initially thought of using d-flex align-items-stretch, but it seems like it is not working because those elements are not within the same row ...

Issues with $.post function causing HTML to be displayed instead of the intended value

I have a question about sending the value of an HTML element to the server using POST. When I alert the result, I expect to only see the value but I am also getting the HTML content of the PHP file included in my code. Why is this happening? function post ...

What methods can we use to transform Bootstrap rows and columns to resemble a table design?

Attempt number one did not work due to padding issues in the columns. Attempt number two also failed, leading me to believe I may be making a mistake somewhere. This is what I am aiming for: https://i.sstatic.net/yTz6o.png Can anyone provide some assis ...

Determine the Height of the Container once the Font File has Finished Loading

When styling a website with a unique font using @font-face, the browser must download the font file before it can display the text correctly, similar to how it downloads CSS and JavaScript files. This poses an issue in Chrome (v16.0.912.63) and Safari (v5 ...

Submitting the form may cause disruptions for others

I currently have an email subscription form for my newsletter that is managed through PHP. This form appears in the footer of every page on my website. Check out a demonstration on JSFIDDLE While the form itself functions properly, I am encountering issu ...

Placing a JavaScript button directly below the content it interacts with

I am currently working on a button that expands a div and displays content upon clicking. I am facing an issue where I want the button to always be positioned at the bottom of the div, instead of at the top as it is now, but moving it within the parent div ...