【问题标题】:How to add 2nd floating label to input when using 1 div only in bootstrap 5仅在引导程序 5 中使用 1 个 div 时如何将第二个浮动标签添加到输入
【发布时间】:2021-10-08 12:08:00
【问题描述】:

如何在右侧输入字段中添加第二个浮动标签?现在的问题是第二个标签与第一个输入字段中的第一个标签重叠:

<div class="form-floating input-group">                         
    <input type="text" name="" class="form-control delete-from-date" value="" />
    <label for="floatingDateToDelete">startdate</label>
    <span class="input-group-text">till</span>                          
    <input type="text" name="" class="form-control delete-till-date" value="" />
    <label for="floatingDateToDelete">Enddate</label>   
    <button type="submit" class="btn btn-danger delete-multiple-events" name="submit">Delete</button>               
</div>

这是一个你可以看到问题的小提琴:http://jsfiddle.net/1uf0zv2d/6/

浮动标签“结束日期”应出现在右侧输入字段中

【问题讨论】:

    标签: html twitter-bootstrap input label floating-labels


    【解决方案1】:

    每个input+label 组合都需要在其自己的.form-floating 类中。在同一个 div 中有多个输入会导致该问题。此外,每个输入字段需要占位符。

    我已将整个组合移动到一个包含 .input-group 的容器中。您可以在此处查看更改。

    <html>
    
    <head>
      <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
      <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
    </head>
    
    <body>
      <div class="input-group">
        <div class="form-floating">
          <input type="text" class="form-control delete-from-date" id="floatingDateToDelete1" placeholder="startdate" />
          <label for="floatingDateToDelete1">startdate</label>
        </div>
        <span class="input-group-text">till</span>
        <div class="form-floating">
          <input type="text" class="form-control delete-till-date" id="floatingDateToDelete2" placeholder="Enddate" />
          <label for="floatingDateToDelete2">Enddate</label>
        </div>
        <button type="submit" class="btn btn-danger delete-multiple-events" name="submit">Delete</button>
      </div>
    </body>
    
    </html>

    【讨论】:

      猜你喜欢
      • 2021-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-03
      相关资源
      最近更新 更多