简体   繁体   English

如何使输入扩展到Bootstrap 3中的列宽?

[英]How to make input extend to width of column in Bootstrap 3?

I need my 2 inputs which placed inline to have width of parent div which defines col-md-6 and col-md-3 . 我需要放置在行中的2个输入具有定义col-md-6col-md-3的父div的宽度。 Right now inputs are aligned correctly but have width which in one case less than col-md-6 and in second case more than col-md-3 . 现在,输入正确对齐,但宽度在一种情况下小于col-md-6 ,在第二种情况下大于col-md-3 How to make this inputs have width col-md-6 and col-md-3 correspondingly? 如何使此输入的宽度分别为col-md-6col-md-3

<div class="col-md-9">
    <form action="" role="form" class="form-inline">
        <div class="col-md-6">
            <div class="form-group">
                <label for="iR" class="sr-only">i R</label>
                <input type="text" class="form-control" id="iR" placeholder="some mid long explanation" />
            </div>
        </div>
<div class="col-md-3">
            <div class="form-group">
                <label for="iS" class="sr-only">i S</label>
                <input type="text" class="form-control" id="iS" placeholder="some mid long explanation 2" />
            </div>
        </div>
</div>

As others have mentioned, you need to specify custom widths with inline forms. 正如其他人提到的那样,您需要使用内联表单指定自定义宽度。 From the docs : 从文档

Inputs and selects have width: 100%; 输入和选择的宽度为:100%; applied by default in Bootstrap. 默认在Bootstrap中应用。 Within inline forms, we reset that to width: auto; 在嵌入式表单中,我们将其重置为width:auto; so multiple controls can reside on the same line. 因此,多个控件可以位于同一行上。 Depending on your layout, additional custom widths may be required. 根据您的布局,可能需要其他自定义宽度。

In your case, you need to specify width: 100% for both the input and the form-group: 在您的情况下,您需要为输入和表单组指定width: 100%

<div class="form-group" style="width: 100%">

and

<input type="text" class="form-control" id="iR" placeholder="some mid long explanation" style="width: 100%" />

Working example in JSFiddle JSFiddle中的工作示例

Just put style="width: 100%;" 只需输入style =“ width:100%;” on the input; 在输入上; Btw, you are missing a form closing tag. 顺便说一句,您缺少表单结束标记。

Also if you look at bootstraps for any elements you set up most of the time they leave a bit of margins. 同样,如果您在大多数情况下查看引导程序以查找设置的任何元素,它们会留有一些空白。 So if you don't want any margins just change the margins to 0. 因此,如果您不希望有任何边距,只需将边距更改为0。

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

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