简体   繁体   English

如何在引导程序中的输入字段旁边放置图标

[英]How to place icon next to input field in bootstrap

I am using using bootstrap in my project. 我在项目中使用引导程序。 I am creating an edit form in which i have to use some info icons next to input field and in this task i am facing an alignment problem. 我正在创建一个编辑表单,其中我必须在输入字段旁边使用一些信息图标,在此任务中,我面临对齐问题。 Please check this image: 请检查这张图片: 在此处输入图片说明

Notice the huge gap b/w input field and icon and the same problem is with selectlist and duration field. 请注意,巨大的黑白输入字段和图标之间存在差距,而选择列表和持续时间字段同样存在问题。 The html code of this image is: 该图像的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>

I am new with bootstrap and very week in css, so i do not want to write css, is this problem can be solved using bootsrap classes ?? 我是bootstrap的新手,并且在css中非常一周,所以我不想编写css,可以使用bootsrap类解决此问题吗?

Try this 尝试这个

<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>

The classes col-md-X define a "box" for the div. col-md-X类为div定义了一个“框”。 If you place the anchor inside the same div as the textbox, the icon should align. 如果将锚点放置在与文本框相同的div内,则图标应对齐。

Further reading: http://getbootstrap.com/examples/grid/ 进一步阅读: http : //getbootstrap.com/examples/grid/

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

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