简体   繁体   中英

How to align input box with a few sr-only labels in bootstrap

I'm trying to format a form page with bootstrap, some of the inputs have visible labels and some others don't. According to bootstrap documentation (Column sizing section) I have to wrap in "row" classes to set the size of inputs, but when i add sr-only class to some labels it doesn't fit. Any suggestions? Here is the fiddle , the TypeId and DV are not aligned

General Information

                <div class="form-group col-xs-6">
                    <label class="control-label" for="fullname">Full name</label>

                    <input id="fullname" name="fullname" type="text"
                           class="form-control input-md"></input>
                </div>

                    <div class="form-group col-xs-2">
                        <label class="control-label  sr-only" for="TypeId">Type Id</label>

                        <select id="TypeId" name="TypeId" class="form-control  input-md ">
                            <option value="CC">CC</option>
                            <option value="NIT">NIT</option>
                            <option value="NUIP">NUIP</option>
                            <option value="CE">CE</option>
                            <option value="PA">PA</option>
                            <option value="TI">TI</option>
                        </select>
                </div>
                <div class="form-group col-xs-3">
                    <label class="control-label" for="id">Id</label>

                    <input id="id" name="id" type="text" class="form-control input-md"></input>
                </div>
                <div class="form-group col-xs-1">
                        <label class="control-label sr-only" for="DV">DV</label>
                        <input id="DV" name="DV" type="text"
                               class="form-control input-md"></input>
                </div>


            </fieldset>

A quick (and hacky!) fix is to add another label after your sr-only label that contains only a &nbsp; and no for attribute:

DEMO

<div class="form-group col-xs-2">
    <label class="control-label  sr-only" for="TypeId">Type Id</label>
    <label class="control-label">&nbsp;</label>
    <select id="TypeId" name="TypeId" class="form-control  input-md ">
        <option value="CC">CC</option>
        <option value="NIT">NIT</option>
        <option value="NUIP">NUIP</option>
        <option value="CE">CE</option>
        <option value="PA">PA</option>
        <option value="TI">TI</option>
    </select>
</div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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