【问题标题】:Issue when trying to align text and textbox in one line inside the form?尝试在表单内的一行中对齐文本和文本框时出现问题?
【发布时间】:2022-01-30 17:46:29
【问题描述】:

<div class="col-sm-12 col-md-12 text-center">
  <h1>Example Horizontal Form Bootstrap</h1>
</div>
<div class="col-sm-12 col-md-4"></div>
<div class="col-sm-12 col-md-4 text-center">
  <form class="form-horizontal">
    <div class="form-group">
      <label for="inputEmail3" class="col-sm-2 control-label">Enter your Email here........! Hello </label>
      <div class="col-sm-10">
        <input type="email" class="form-control" id="inputEmail3" placeholder="Email">
      </div>
    </div>
    <div class="form-group">
      <label for="inputPassword3" class="col-sm-2 control-label">Enter your Email here........! Hello</label>
      <div class="col-sm-10">
        <input type="password" class="form-control" id="inputPassword3" placeholder="Password">
      </div>
    </div>
  </form>

我想将“文本和文本框”放在一行中。目前,我在文本框旁边的多行中获取文本,如下所示。

【问题讨论】:

    标签: html css bootstrap-4


    【解决方案1】:

    你有几个选择。

    选项 1: 减少标签文本和/或增加分配给它的列。示例

    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous">
    
    <div class="container-fluid">
      <div class="row">
        <div class="col-sm-12 col-md-4">
          <form>
            <div class="form-group form-row">
              <label for="inputEmail3" class="col-sm-3 col-form-label text-sm-right">Email</label>
              <div class="col-sm-9">
                <input type="email" class="form-control" id="inputEmail3" placeholder="Email">
              </div>
            </div>
            <div class="form-group form-row">
              <label for="inputPassword3" class="col-sm-3 col-form-label text-sm-right">Password</label>
              <div class="col-sm-9">
                <input type="password" class="form-control" id="inputPassword3" placeholder="Password">
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>

    选项 2:您可以使用 text-truncate 类截断任何溢出文本。示例

    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous">
    
    <div class="container-fluid">
      <div class="row">
        <div class="col-sm-12 col-md-4">
          <form>
            <div class="form-group form-row">
              <label for="inputEmail3" class="col-sm-3 col-form-label text-sm-right text-truncate">Enter your Email here........! Hello</label>
              <div class="col-sm-9">
                <input type="email" class="form-control" id="inputEmail3" placeholder="Email">
              </div>
            </div>
            <div class="form-group form-row">
              <label for="inputPassword3" class="col-sm-3 col-form-label text-sm-right text-truncate">Enter your Password here........! Hello</label>
              <div class="col-sm-9">
                <input type="password" class="form-control" id="inputPassword3" placeholder="Password">
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>

    【讨论】:

      猜你喜欢
      • 2019-05-16
      • 2021-09-02
      • 1970-01-01
      • 2013-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-22
      相关资源
      最近更新 更多