我在项目中使用bootstrap。我正在创建一个编辑表单,我必须在输入字段旁边使用一些信息图标,在这个任务中我面临对齐问题。请检查此图片:
注意巨大的差距黑白输入字段和图标,同样的问题是选择列表和持续时间字段。此图片的html代码为:
<div class="row">
<div class="col-md-6 form-group">
@Html.LabelFor(p => p.Services[0].FixedTimeSlot, new { @class = "col-md-5 control-label small" })
<div class="col-md-5">
@Html.TextBoxFor(p => p.Services[0].FixedTimeSlot, new { @class = "form-control input-sm", data_bind = "value: FixedTimeSlot" })
@Html.ValidationMessageFor(p => p.Services[0].FixedTimeSlot, "", new { @class = "help-block" })
</div>
<div class="col-md-2">
<a tabindex="-1" href="javascript:void(0);"><span class="fa fa-info-circle text-info icon-ms" data-bind=""></span></a>
</div>
</div>
<div class="col-md-6 form-group">
@Html.LabelFor(p => p.Services[0].Duration, new { @class = "col-md-5 control-label small" })
<div class="col-md-7">
<div class="row">
<div class="col-md-6">
@Html.TextBoxFor(p => p.Services[0].Duration, new { @class = "form-control input-sm", data_bind = "value: Duration" })
</div>
<div class="col-md-6">
<select class="form-control input-sm" data-bind="options: $parents[1].timeUnits, optionsText: 'unit', optionsValue: 'value', value: selectedTimeUnit"></select>
</div>
</div>
@Html.ValidationMessageFor(p => p.Services[0].Duration, "", new { @class = "help-block" })
</div>
</div>
</div>
我是bootstrap的新手,在css中非常周,所以我不想写css,这个问题可以用bootrap类解决吗?
答案 0 :(得分:1)
试试这个
<div class="col-md-6 form-group">
@Html.LabelFor(p => p.Services[0].FixedTimeSlot, new { @class = "col-md-5 control-label small" })
<div class="col-md-5">
@Html.TextBoxFor(p => p.Services[0].FixedTimeSlot, new { @class = "form-control input-sm", data_bind = "value: FixedTimeSlot" })
@Html.ValidationMessageFor(p => p.Services[0].FixedTimeSlot, "", new { @class = "help-block" })
<a tabindex="-1" href="javascript:void(0);"><span class="fa fa-info-circle text-info icon-ms" data-bind=""></span></a>
</div>
</div>
类col-md-X为div定义了一个“框”。 如果将锚点放在与文本框相同的div中,则图标应对齐。