Designing a webpage layout using Bootstrap 4 that includes a horizontal/inline form and two columns

Just when I felt confident in my understanding of bootstrap, it seems to be giving me trouble :(

I am aiming to create a layout with 2 columns, each containing a question followed by a small text box for entering a number.

Here is an example of the layout I have in mind

__ indicates a small text box below

_____________________________________________________________________________________________
Group 1                                                     |  Group 2    
1. Are you Prone to Infection, colds, coughs, or flu? ___   | 1. What is your weight ____                                                | 2. adfafafa 
2. Do you have inflammation, Heat spots ? __                |   

My struggle lies in achieving the desired horizontal alignment as they are either wrapping incorrectly or too far apart/ close to each other.

<div class="row">
    <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6" style="border:1px solid black;">
        <div class="form-inline">
            <label>1. Are you Prone to Infection, colds, coughs, or flu? </label>
            <input id="group1A" [(ngModel)]="group1A" name="group1A" style="width: 5px;" type="text" class="form-control" placeholder="">
            <br>
            <label for="group1B">Do you have inflammation, Heat spots ? </label>
            <input id="group1B" [(ngModel)]="group1B" name="group1B" type="text" class="form-control" placeholder="">

            <label for="group1C">Do you have specific pain (printed form - list on Back)</label>
            <input id="group1C" [(ngModel)]="group1C" name="group1C" type="text" class="form-control" placeholder="">

            <label for="group1D">Do you have swelling?</label>
            <input id="group1D" [(ngModel)]="group1D" name="group1D" type="text" class="form-control" placeholder="">

            <label for="group1E">Do you have pus, open sores, skin problems, mucus formation?</label>
            <input id="group1E" [(ngModel)]="group1E" name="group1E" type="text" class="form-control" placeholder="">
        </div>
    </div>
    <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6" style="border:1px solid black;">
        <div class="form-inline">
        ......
    </div>
</div>

Answer №1

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<div class="row">
    <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6" style="border:1px solid black;">
      <div class="form-group row">
        <label class="col-sm-12 col-form-label">1. Question number one ? <input id="group1A" [(ngModel)]="group1A" name="group1A" type="text" class="form-control" style="width:50px; display:initial !important;" placeholder=""></label>
      </div>
      <div class="form-group row">
        <label class="col-sm-12 col-form-label" for="group1B">Question number two? <input id="group1B" [(ngModel)]="group1B" name="group1B" type="text" class="form-control" style="width:50px; display:initial !important;" placeholder=""></label>
      </div>          
    </div>
    <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6" style="border:1px solid black;">
        <div class="form-inline">
        ......
    </div>
</div>

Answer №2

In my opinion, it would be more efficient to simply use "col-md-6" for each group.

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<div class="container">
  <div class="row">

    <div class="col-md-6 form-inline" style="border:1px solid black;">
      GROUP 1
    </div>

    <div class="col-md-6 form-inline" style="border:1px solid black;">
      GROUP 2
    </div>

  </div>
</div>

For reference, you can visit https://getbootstrap.com/docs/3.3/css/#grid-example-basic
Here is an example:

<div class="row">
  <div class="col-md-6">.col-md-6</div>
  <div class="col-md-6">.col-md-6</div>
</div>

Answer №3

It appears that you might have forgotten to include the "mr-screensize-marginsize" (margin-right) classes in your input elements (e.g. mr-md-5) - for more information, please visit

<input id="group1A" [(ngmodel)]="group1A" name="group1A" style="width: 5px;" type="text" class="form-control mr-md-5 mr-sm-5 mr-lg-5" placeholder="">

Answer №4

If you're looking for a solution, consider the following code snippet:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<div class="row">
    <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6" style="border:1px solid black;">
      <div class="form-group row">
        <label class="col-sm-8 col-form-label">1. Are you Prone to Infection, colds, coughs, or flu? </label>
          <div class="col-sm-4">
            <input id="group1A" [(ngModel)]="group1A" name="group1A" type="text" class="form-control" placeholder="">
          </div>
      </div>
      <div class="form-group row">
        <label class="col-sm-8 col-form-label" for="group1B">Do you have inflammation, Heat spots ? </label>
        <div class="col-sm-4">
          <input id="group1B" [(ngModel)]="group1B" name="group1B" type="text" class="form-control" placeholder="">
        </div>
      </div>          
    </div>
    <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6" style="border:1px solid black;">
        <div class="form-inline">
        ......
    </div>
</div>

For more information on Bootstrap 4, visit the documentation here:

https://getbootstrap.com/docs/4.0/components/forms/

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

React JS progress circle bar is a simple and effective way to visualize

Currently, I am in the process of developing a progress circle bar that will function as a timer alongside sliders. Each slide is intended to have its own corresponding progress bar. While I have managed to create the bars individually, I am facing challe ...

Is there a way to prevent this picture from shifting?

I am currently revamping the content on my work website using Joomla. I have received the old copy and now I need to enhance it. The website in question is 24x7cloud.co.uk. At the bottom of the page, I aim to include an "Accreditation's" section. Howe ...

What is the best way to showcase an image before saving it in the database after it has been selected?

I am currently working on creating a feature where, upon selection of an image, a preview of the selected image is displayed before hitting the save button. Here's what I have in mind: <div class="row align-items-center my-5"> <div cl ...

Troubleshooting Alignment Problems in Bootstrap 4 Tables

Having trouble aligning certain items. In thisFiddle, I have two options: Option1 and Option2. I want to align the toggle switches with the ones in the first two rows. Specifically, I want the toggle switches to be in the second column of the table and t ...

Using Polymer in Chrome Extension content script

Currently, I am experimenting with incorporating Polymer into a chrome extension. My main objective is to take advantage of styling encapsulation in order for my content scripts to operate independently from the CSS on the visited webpage. To begin, I hav ...

Stopping all other audio players when a new one is played in Angular

I am in the process of creating a website using Angular to showcase my music, and I am looking for a script that will pause other audio players when a new one is played. Does anyone have a solution for this? HTML <div> <img src="{{ image }}" a ...

Playing around with adjusting the size of a div that is positioned absolutely on the right side

Snippet: http://jsfiddle.net/scottbeeson/TU6Zw/ HTML Code: <div id="itemMap" class="shadow"> <div class="mapHeader">List of Items</div> <div class="mapItem">Item 1</div> <div class="mapItem">Item 2</div& ...

Creating an engaging user experience with a Django form

Creating a dynamic calculator <div id="calculator"> <h2>Calculate the price of sawing materials</h2> <form method="post" action="{% url 'products' %}"> {% csrf_token %} & ...

Troubleshooting Browser Behavior: Back Button Not Loading Page - jQuery and HTML5

I've built a dynamic slideshow using jQuery to change images with seamless transitions. To enhance user experience, I'm also updating the page title and URL without triggering a page reload. The code snippet below illustrates how I achieve this: ...

Submit Form using Ajax - Update text in HTML element upon click

As I am working on developing a message system, I encountered an issue where the message content is not opening correctly in my template when clicking the "See" button. My intention is to implement an Ajax call that will replace the content with jQuery .te ...

The HTML and body elements do not possess a width of 100% within the document

When viewing my portfolio site on smaller screens such as 425px and below, there is a white gap on the right side. This issue arises because the HTML and body elements do not inherit full width by default. Do you know why this happens and how I can resol ...

Using Three.js to incorporate an external JavaScript file into an HTML document

Currently experimenting with three.js and successfully rendered a 3D cube using HTML. Here's a snippet of the HTML code: <div id="render" class="center-block"> <script> // JavaScript code for rendering the 3D cube goes here </script&g ...

Step-by-step guide on aligning an image to the left of text in a Material UI table column

After experimenting with inline styling, I attempted to move the images next to the text in a specific column. However, there are some rows where the images overlap or the text is positioned too far to the right, as shown in this image: https://i.stack.im ...

Can we implement add_image_size along with get_theme_file_uri?

I have a custom field in ACF for images linked to my custom post type. In case no image is selected, it should default to an image from the media library. If the check for get_field('box_image') returns empty or null, I want to use a default ima ...

What is the best way to shorten a string with jquery?

If the name of the string surpasses a certain limit, indicated by character count, three dots will be displayed. To achieve this, replace the last 3 characters with …. For example, if a name has 30 characters but only 15 can fit in the screen label field ...

Creating a clickable pagination box involves utilizing CSS to style the entire <li> element with the necessary properties

Is there a way to make the entire LI box clickable for the pagination box? The HTML and CSS parts are functioning correctly, as I am able to click the link with the page number to navigate to the next page. However, the issue arises when trying to click t ...

What is the best way to apply styles based on specific screen widths while still having default styles for other screen sizes?

Here is the code snippet I am working with: <TableCell sx={{ borderBottom: { xs: 0, lg: 1 } }}> <Typography variant="body2">{account.name} ({account.currency})</Typography> </TableCell> I am facing an issue where the ...

Jquery problems impacting every element rather than only one

I'm currently experimenting with a small project where I have multiple div elements containing an image, h1 tag, and p tag all sharing the same class name. My goal is to add CSS effects that make the h1 tag and p tag slide into view and become visible ...

What could be the reason for my jQuery Bootstrap form not sending properly formatted JSON to the REST service?

I have incorporated Bootstrap and jQuery into my web page. Upon a button click, a modal dialog box appears with a simple form. When submitted, the form content is sent as JSON to my RESTful web service. Take a look at the modal dialog below... <!-- M ...

Attempting to incorporate images alongside menu items

Here is a list of menu items. Please take note that I have assigned the image class to the City menu item. <p:submenu label="Address"> <p:menuitem value="Country" url="/secured/country.xhtml?redirect=true" /> <p:menuitem value="Stat ...