Horizontal Form in Bootstrap - issue with the class "form-group"

The horizontal form isn't aligning the labels and fields horizontally.

On my page, I have a form with 4 fields, a submit button, and a list at the bottom. The form is enclosed in a <p-panel > and the list is enclosed in another <p-panel >.

I want the form to be aligned like a bootstrap horizontal form. The version of my Bootstrap.min.css is Bootstrap v4.5.0.
Here is the code:

<p-messages [(value)]="msgs"></p-messages>
  <p-panel >
    <p-header>
        Header Example
    </p-header>
    <form [formGroup]="testForm"  (ngSubmit)="submitForm(testForm.value)" class="form-horizontal">
      <div class="form-group"  *ngIf="!this.isTest" style="padding:10px;">
        <label class="control-label col-sm-2">Name:</label>
        <div class="col-sm-10">
          {{this.name}}
        </div>
      </div>
      ...

I am seeking for assistance on achieving bootstrap horizontal alignment as demonstrated on this page.

However, the rendered result in Chrome displays labels on top of inputs instead of beside them, like this:

Name: 
ABCTEST

In IE, the layout also appears one below the other with the label on top followed by input/button/date/text area vertically positioned. I'm unsure what is incorrect in my code.

I have referenced Bootstrap in my angular.json file under "src/assets/css/bootstrap.min.css". When inspecting elements in Chrome, it points to the bootstrap.min.css file.

Your insights would be greatly appreciated.

Answer №1

Give this a shot, it may not have been successful for you because you forgot to include the bootstrap embed.

<html>
  <head>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">

    <title>Bootstrap Horizontal Form</title>
  </head>
  <body style="padding: 50px;">

    <form>
      <div class="form-group row">
        <label for="inputEmail3" class="col-sm-2 col-form-label">Name</label>
        <div class="col-sm-10">
          <input type="name" class="form-control" id="name" placeholder="Name">
        </div>
      </div>
      <fieldset class="form-group">
        <div class="row">
          <legend class="col-form-label col-sm-2 pt-0">Choose</legend>
          <div class="col-sm-10">
            <div class="form-check">
              <input class="form-check-input" type="radio" name="gridRadios" id="option1" value="option1">
              <label class="form-check-label" for="gridRadios1">
                Option 1
              </label>
            </div>
            <div class="form-check">
              <input class="form-check-input" type="radio" name="gridRadios" id="option2" value="option2">
              <label class="form-check-label" for="gridRadios2">
                Option 2
              </label>
            </div>
            <div class="form-check disabled">
              <input class="form-check-input" type="radio" name="gridRadios" id="option3" value="option3">
              <label class="form-check-label" for="gridRadios3">
                Option 3
              </label>
            </div>
          </div>
        </div><br>
      </fieldset>
      <div class="form-group row">
        <div class="col-sm-2">Select Names</div>
        <div class="col-sm-10">
          <div class="form-check">
            <input class="form-check-input" type="checkbox" id="name1">
            <label class="form-check-label" for="name1">
              Name 1
            </label><br>
            <input class="form-check-input" type="checkbox" id="name2">
            <label class="form-check-label" for="name2">
              Name 2
            </label><br>
            <input class="form-check-input" type="checkbox" id="name3">
            <label class="form-check-label" for="name3">
              Name 3
            </label><br>
          </div>
        </div>
      </div>
      <div class="col-md-3 mb-3">
        <label for="validationCustom05">Start Date</label>
        <input type="date" class="form-control" id="start-date" name="start-date">
      </div>
      <div class="col-md-3 mb-3">
        <label for="validationCustom05">End Date</label>
        <input type="date" class="form-control" id="end-date" name="end-date">
      </div>
      <div class="form-group">
        <label for="message">Message</label>
        <textarea class="form-control" id="message" rows="3" name="message" placeholder="Message"></textarea>
      </div>
      <div class="form-group row">
        <div class="col-sm-10">
          <button style="width: 122.5%;" type="submit" class="btn btn-primary">Sign in</button>
        </div>
      </div>
    </form>

    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="83f3ecf3f3e6f1ade9f0c3b2adb2b5adb3">[email protected]</a>/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
  </body>
</html>

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

Step-by-step guide on setting an array value to a different input type with jQuery

Just starting out with jQuery and could use some help. How can I use jQuery to assign an array input value to another input field? <tr> <td><label>Date:</label><input type="date" name="PostingDate[]" id="date" style="text-al ...

Customize your AutoComplete with MUI styling

Upon taking over a project, I found myself working with material ui for the first time. Here is an excerpt from my code: <FormControl fullWidth> <InputLabel className={className} htmlFor={id} error={error} > ...

Difficulty in finding class using Selenium's xpath method

I'm currently engaged in a data scraping project where I'm running a for loop to go through 50 URLs, all of which lead to the same page but with different information. My objective is to extract various data elements and compile them into a CSV f ...

Form nesting with control value accessor usage

In my current setup, I have one container component with two child components: Trip and Contact. To nest the child components within the parent, I have implemented ControlValueAccessor. I created an AbstractValueAccessor class that implements ControlValueA ...

Is there a method to update the status of a Jquery UI Mobile navbar using Javascript?

I have created a navigation bar using the Jquery mobile UI 1.01 framework; <div id="footer" data-role="footer" data-position="fixed"> <div data-role="navbar"> <ul> <li><a href="#" onClick="toggle_units();" clas ...

Is it possible to conceal or disregard text elements from the web browser search function by using CTRL+F?

I have a complex web application interface with a dedicated area for content display. Is there a way to ensure that when users utilize the browser's text search function (CTRL+F), the UI elements are ignored and only the actual content is searched? ...

During the process of downgrading a component, the @ContentChild(TemplateRef) becomes null

When utilizing this code within any component: @ContentChild(TemplateRef) public myTemplate: TemplateRef<any>; It functions properly in Angular 2, I can access it with: this.myTemplate However, after downgrading the component to make it compatibl ...

Ways to create intersecting borders at the corners of a division

Is there a technique to expand the borders of a div by 1 or 2 pixels in each direction so that they create a cross at each corner? https://i.stack.imgur.com/mUAxM.png ...

Slowing down mouse movement with D3 "mousemove" event

I have an Angular application that utilizes D3 with SVG elements. There is a "mousemove" event implemented within the app, which was working fine initially despite the complexity of the application. However, after some recent changes (that were not relat ...

Trouble with running the "npm run tsc" command in Angular 2 beta

I'm facing an issue with compiling my Typescript using the command npm run ts. What's odd is that I can successfully compile and run it by running npm start. Below is the log: 0 info it worked if it ends with ok 1 verbose cli [ 'node' ...

Translate language in an Angular file using TypeScript

const typeArray= [ { id: 'PARENT', name: '{{ appConstants.type.PARENT | translate }}' }]; What is the best way to incorporate translations when declaring an array in a TypeScript file? ...

Creating a custom color scheme for school events

I am currently studying coding in school and have just started my coding journey 3 months ago. This is my first post on a forum, so please be kind! I am encountering an issue with the drag function. For an extracurricular activity for school kids, I came ...

TSLint throws an error, expecting either an assignment or function call

While running tslint on my angular project, I encountered an error that I am having trouble understanding. The error message is: expected an assignment or function call getInfoPrinting() { this.imprimirService.getInfoPrinting().subscribe( response => ...

Exploring the world of dynamic locale with Angular 5 Pipes

My current situation involves having apps created in angular 4 and I am contemplating upgrading to angular 5. After researching how locale is managed in the pipes, it appears that upgrading may not be feasible. It seems that there are two options provided: ...

Generating dynamic tables using JQuery is not possible

This script is intended to generate a table and convert it into a canvas. Clicking on a cell should change its color to the selected color from the color picker input is retrieved from text boxes and the color picker, and executed upon submitting I need t ...

Validating variables in a PHP form submission

I am currently facing an issue that has me stumped. I have a basic HTML form that needs verification upon submission. If the values submitted fail validation, I need to redirect back to the form and highlight the errors. While I've done similar valida ...

Dynamically size and position elements to fit perfectly within the container

I am currently facing a challenge with my absolutely positioned elements that have different position.top and height values generated from the database. The main goal is to resolve collisions between these elements by shifting them to the right while adju ...

The content box is not aligning properly with the content inside, causing it to vanish instead of overflowing with

There seems to be an issue with the content boxes on one of my pages. They all use the same CSS, but for some reason, there is a scroll bar in one of the content boxes and the footer doesn't align properly. The problem arises when I add overflow:auto ...

Update and insert fresh information into the Angular file

I currently have a CSV file stored in my assets folder. The file path is 'assets/data.csv' Here is how I am able to read the contents of the file: readLocalCSVFile() { this._http.get('assets/data.csv', { responseType: 'text ...

Text that is not aligned in the middle and has a colored background

After setting up a flexbox container with some flex-items, I encountered an issue: When clicking on either "Overview" or "Alerts", the white background border is not displayed. To highlight the selected item, a class called .selected is triggered which ad ...