简体   繁体   English

引导表单对齐问题

[英]Bootstrap form alignment issue

Trying to align two form elements side by side to create an hours per week field 尝试并排对齐两个表单元素以创建每周工作时间字段

eg 例如

Hours per week (box here) - (box here) 每周小时数(在此框内)-(在此框内)

but when I use two col-md-2 with a - between them I get the result of 但是当我使用两个带有-的col-md-2时,我得到的结果

Hours per week (box here) (box here) - 每周小时数(在此框内)(在此框内)-

Anyone have a solution to display the - between the two boxes? 任何人都可以在两个方框之间显示-吗? I've tried using 3 col-md-1 but the alignment gets all out of whack! 我试过使用3 col-md-1,但对齐方式完全无效!

The below code follows Bootstrap form construction. 以下代码遵循Bootstrap表单构造。 Using .input-group allows you to nest .input-group-addon between to fields with the .form-control class - though you do need to specify a width (hence the .col-xs-9 ). 使用.input-group允许您在.form-control类的字段之间嵌套.input-group-addon尽管您确实需要指定宽度(因此.col-xs-9 )。

 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <form> <div class="form-group"> <label class="col-xs-3 control-label" for="HoursPerWeek">Hours Per Week</label> <div class="col-xs-9"> <div class="input-group"> <input type="text" id="BoxOne" class="form-control"> <span class="input-group-addon">-</span> <input type="text" id="BoxTwo" class="form-control"> </div> </div> </div> </form> 

Solution without the bootstrap grid 没有引导网格的解决方案

  <form class="inline"> <div> <label for="HoursPerWeek">Hours Per Week</label> <input type="text" id="BoxOne"> <label for="#">-</label> <input type="text" id="BoxTwo"> </div> </form> 

Solution using the bootstrap grid 使用引导网格的解决方案

  <form> <div class="form-group"> <label class="col-md-3" for="HoursPerWeek">Hours Per Week</label> <input class="col-md-3" type="text" id="BoxOne"> <label class="col-md-3" for="#">-</label> <input class="col-md-3" type="text" id="BoxTwo"> </div> </form> 

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

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