简体   繁体   English

如何使用引导程序将输入与最后一个标签行对齐

[英]how to align input with the last label line with bootstrap

I've made a bootstrap form, and i want align my input with the last text line of his refferencial label: 我制作了一个引导表单,我想将输入内容与他的参考标签的最后一行对齐:

this is my code: 这是我的代码:

  <div class="form-group"> <label class="col-sm-2 control-label">Date de début des soins:</label> <div class="col-sm-3"> <input type="text" class="form-control" placeholder="Product name"> </div> <div class="col-sm-1"> </div> <label class="col-sm-2 control-label">Durée des soins:</label> <div class="col-sm-3"> <input type="text" class="form-control" placeholder="Product name"> </div> <div class="col-sm-1"> </div> </div> 

https://jsfiddle.net/Tibuakaw/q945k4eg/ https://jsfiddle.net/Tibuakaw/q945k4eg/

how to fix it ? 如何解决?

在此处输入图片说明

A table layout is a quick way of doing it 表格布局是一种快捷的方法

<table>
    <tr>
        <td>Date de début des soins:</td>
        <td> <input type="text" class="form-control" placeholder="Product name"></td>
    </tr>
    <tr>
        <td>Durée des soins:</td>
        <td> <input type="text" class="form-control" placeholder="Product name"></td>
    </tr>
</table>

https://jsfiddle.net/g8m16v48/ https://jsfiddle.net/g8m16v48/

 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script> <div class="form-group"> <div class="row"> <label class="col-sm-4 col-xs-4 control-label">Date de début des soins:</label> <div class="col-sm-8 col-xs-8"> <input type="text" class="form-control" placeholder="Product name"> </div> </div> <div class="row"> <label class="col-sm-4 col-xs-4 control-label">Durée des soins:</label> <div class="col-sm-8 col-xs-8"> <input type="text" class="form-control" placeholder="Product name"> </div> </div> </div> 

 .control-label{ float:left; } 
 <div class="form-group"> <label class="col-sm-2 control-label">Date de début des soins:</label> <div class="col-sm-3"> <input type="text" class="form-control" placeholder="Product name"> </div> <div class="col-sm-1"> </div> <label class="col-sm-2 control-label">Durée des soins:</label> <div class="col-sm-3"> <input type="text" class="form-control" placeholder="Product name"> </div> <div class="col-sm-1"> </div> </div> 

For those looking for the answer to this: 对于那些正在寻找答案的人:

You can do it with vertical-align: baseline The label needs to be wrapped in an inline-block element and the line-height needs to be set on the outer container. 您可以使用vertical-align:基线将标签包裹在inline-block元素中,并将行高设置在外部容器上。 In the sample below, the first one is using divs, the second is using a table. 在下面的示例中,第一个使用div,第二个使用表。

 .row { vertical-align: baseline; } .label { display: inline-block; } /* For demonstration purposes */ .label { width: 100px; } 
 <div class="row" style="white-space: nowrap;"> <span class="label" style="white-space: normal;">Date de début des soins:</span> <input type="text" class="form-control" placeholder="Product name"> </div> <div class="row" style="white-space: nowrap;"> <span class="label" style="white-space: normal;">Durée des soins:</span> <input type="text" class="form-control" placeholder="Product name"> </div> <hr> <table> <tr class="row"> <td> <span class="label">Date de début des soins:</span> </td> <td> <input type="text" class="form-control" placeholder="Product name"> </td> </tr> <tr class="row"> <td><span class="label">Durée des soins:</span></td> <td> <input type="text" class="form-control" placeholder="Product name"> </td> </tr> </table> 

https://jsfiddle.net/v9x3wote/ https://jsfiddle.net/v9x3wote/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM