简体   繁体   English

控制文字输入的宽度

[英]Control width of text input

I'm trying to create a single row with search inputs (a text input and an 'attached' button) at the left, and a button at the right (the bit above the grid): 我正在尝试创建一个单行,左侧是搜索输入(文本输入和“附加”按钮),而右侧是按钮(网格上方的位):

我想要的样品

Here's the code: 这是代码:

<form class="row form-inline">
    <div class="form-group col-xs-6">
        <div class="input-group">
            <input name="search" type="text" class="form-control input-sm">
            <span class="input-group-btn">
                <button class="btn btn-default btn-sm" type="submit">
                    <span class="glyphicon glyphicon-search"></span>  Search
                </button>
            </span>
        </div>
    </div>

    <div class="form-group col-xs-6">
        <a class="btn btn-default btn-sm pull-right" href="#">
            <span class="glyphicon glyphicon-user"></span>  Create
        </a>
    </div>
</form>

The problem is that the width of text input is too small at the 'lg' and 'md' browser sizes, and only increases to something that looks OK when the browser is at smaller sizes. 问题在于,在“ lg”和“ md”浏览器尺寸下,文本输入的宽度太小,仅当浏览器尺寸较小时,才增加到看起来可以的程度。 What's the best way to increase the width of the search input at larger browser sizes? 在较大的浏览器尺寸下增加搜索输入宽度的最佳方法是什么?

why dont you set the width on the input using bootstrap classes? 为什么不使用引导程序类在输入上设置宽度? eg 例如

<input name="search" type="text" class="form-control col-lg-10 col-md-8 col-sm-12 col-xs-12">

Try this as well 也尝试一下

<form class="row form-inline">
    <div class="form-group col-md-8">
        <div class="input-group">
            <input name="search" type="text" class="form-control col-md-6">
            <span class="input-group-btn col-md-2">
                <button class="btn btn-default" type="submit">
                    <span class="glyphicon glyphicon-search"></span>  Search
                </button>
            </span>
        </div>
    </div>

    <div class="form-group col-md-4">
        <a class="btn btn-default pull-right" href="#">
            <span class="glyphicon glyphicon-user"></span>  Create
        </a>
    </div>
</form>

As you can see in Bootstrap DOC form-inline require setting a width for input componentes: 如您在Bootstrap DOC表格内联中所见,需要为输入组件设置宽度:

http://getbootstrap.com/css/#forms-inline http://getbootstrap.com/css/#forms-inline

To solve that problem I have custom classes for that: 为了解决这个问题,我为此定制了类:

.input-width-X {width: X}
.input-width-Y {width: Y}
...

and use media queries for this classes in order to apply them just when you are not in XS mode, because Bootstrap set 100% width on it. 并针对此类使用媒体查询,以便仅在您不在XS模式下时才应用它们,因为Bootstrap对其设置了100%的宽度。

Sorry about my english :) 对不起我的英语:)

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

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