【问题标题】:Bootstrap Horizontal Form - class="form-group" not workingBootstrap 水平表单 - class="form-group" 不起作用
【发布时间】:2020-10-26 04:23:51
【问题描述】:

表单水平未水平对齐标签和字段。 我有一个带有表单(有 4 个字段)的页面,底部有一个提交和一个列表。我用于表格,另一个用于列表。 我希望表格与引导水平表格一样对齐。我的 bootstrap.min.css 就是这个版本 -> Bootstrap v4.5.0。 我的代码如下:

<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>
            <div class="form-group"  *ngIf="this.isTest" style="padding:10px;">
                    <label class="control-label col-sm-2">Display For:</label>
                    <div class="col-sm-10">
                    <p-listbox formControlName="names" [options]="names" [(ngModel)]="selectedName" [style]="{'width':'300px'}"  [listStyle]="{'max-height':'100px'}" [multiple]="true" [checkbox]="true" [filter]="true" optionLabel="name">
                        <p-header>
                            Choose
                        </p-header>
                        </p-listbox>
                    </div>
                    </div>
                    <div class="form-group" *ngIf="this.isTest">
                    <p>Selected Names: <span *ngFor="let c of selectedName" style="margin-right: 10px">{{c.name}}</span></p>
            </div>
            <div class="form-group" >
                    <label class="control-label col-sm-2">Start Date:</label>
                    <div class="col-sm-10">
                        <p-calendar formControlName="startDate" [showIcon]="true"></p-calendar>
                        <span style="margin-left:35px">{{startDate|date}}</span>
            </div>
            </div>
            <div class="form-group" >
                <label class="control-label col-sm-2">End Date:</label>
                <div class="col-sm-10">
                        <p-calendar formControlName="endDate" [showIcon]="true"></p-calendar>
                        <span style="margin-left:35px">{{endDate|date}}</span>
                    </div>
            </div>


            <div class="form-group" >  
                    <label class="control-label col-sm-2">Message:</label>
                    <div class="col-sm-10">
                      <textarea rows="5" formControlName="message" class="form-control"  pInputTextArea ></textarea>                     
                    </div>
                    <div class="col-sm-3"></div>
            </div>

    
            <div>
                    <label class="control-label col-sm-4">
                        <button type="submit" class="btn btn-primary" >    Submit  </button>
                    </label>
                </div>
            </form> 
   </p-panel>         
   <p-panel >
        <sampleList [sampleLi]="sampleLi"></sampleList>
</p-panel>

我正在寻找类似此页面Text的引导水平对齐

但是上面用 chrome 渲染的就是下面的一个

Name: 
ABCTEST

在 IE 中,我在垂直定位的顶部输入按钮/日期/文本区域下方的另一个标签下方得到了相同的内容。我不明白我的代码有什么问题。 我的引导程序在我的 angular.json 文件“src/assets/css/bootstrap.min.css”中被引用。 chrome 中的检查元素指向 bootstrap.min.css 文件。 任何意见高度赞赏?

【问题讨论】:

  • 尝试将表单标签中的 class="form-horizo​​ntal" 改为 class="form-inline"
  • @aje form-inline 将所有字段对齐在同一行中。我的要求是将每个 div 对齐在不同的行中。
  • 在 bootstrap 4 中有一个新的类。这里有一个参考 getbootstrap.com/docs/4.5/components/forms/#horizontal-form

标签: html css angular bootstrap-4 angular-ui-bootstrap


【解决方案1】:

试试这个,它可能不适合你,因为你没有嵌入引导程序。

<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/popper.js@1.16.0/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>

【讨论】:

    猜你喜欢
    • 2017-10-26
    • 2014-01-24
    • 1970-01-01
    • 2014-04-10
    • 2021-12-26
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多