Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

input width in form-inline bootstrap 3

I don't understand, how I can customize an input (form-control) width in Bootstrap 3?

<header>
    <div class="container">
        <div class="row">
            <form role="form" class="form-inline">
                  <div class="form-group">
                      <input type="text" class="form-control" placeholder="Почтовый идентификатор" id="search"> 
                  </div>
                    <input type="button" class="btn  btn-success" value="Найти" onclick="window.location.href = '/result/'+document.getElementById('search').value">
            </form>
        </div>
    </div>
</header>

Can I do it without some styles (like width in pixels)?

like image 417
Konstantin Rusanov Avatar asked Jun 01 '14 16:06

Konstantin Rusanov


People also ask

How do I change the width of a bootstrap input?

Change the size of the input groups, by adding the relative form sizing classes like . input-group-lg, input-group-sm, input-group-xs to the . input-group itself.

How do you change the width of an input-group?

To set the width of the input-group-text , just change the value of the flex of the input-group , for instance, as seen above 30% of the total width.

How do I change the size of the input box in bootstrap 4?

Set the heights of input elements using classes like . input-lg and . input-sm . Set the widths of elements using grid column classes like .

How do I make input width fit content?

Use the span. text to fit width of text, and let the input have same size with it by position: absolute to the container.


1 Answers

Update (W3Schools link added): I just spotted that there's a very good answer on this issue available at: w3schools.com/bootstrap/bootstrap_forms_sizing.asp. There are good examples on how to apply either .input-lg and .input-sm for input height or .col-lg-* and .col-sm- for input width.

Original answer: Have you tried to use Bootstrap Grids with your Form and col-xs-.. classes for each input field that needs to be stacked on mobile device. Something like the code below (copy pasted from Bootstrap):

<!-- Stack the columns on mobile by making one full-width and the other half-width -->
<div class="row">
  <div class="col-xs-12 col-md-8">.col-xs-12 .col-md-8</div>
  <div class="col-xs-6 col-md-4">.col-xs-6 .col-md-4</div>
</div>

I applied those col-xs-.. classes on to your form, and got your columns stacked on a mobile device (okay I just made my browser window smaller and it worked).

<div class="container">
        <div class="row">
            <form role="form" class="form-inline">
                <div class="col-xs-12 col-md-2"> 
                    <div class="form-group">  
                        <input type="text" class="form-control" placeholder="Почтовый идентификатор" id="search">  
                    </div>
                </div>
                    <div class="col-xs-6 col-md-1">
                        <input type="button" class="btn  btn-success" value="Найти" onclick="window.location.href = '/result/' + document.getElementById('search').value"/>
                </div>
            </form>
        </div>
    </div> 

On Desktop device I gave those fields smaller values: col-md-2 and col-md-1, but you may want to fine-tune those values the way you like it.

Updated: Have you thought about making your custom colors and sizes by using LESS variables for your input elements, which Bootstrap allows you to do: "Customize Less variables to define colors, sizes and more inside your custom CSS stylesheets."

If you check the Customize part of Bootstrap site. It allows you to customize input elements in your Form. LESS variables such as: @input-bg, @input-color, @input-height-base, @input-border and others could be useful in your case. For instance @input-height-base is by default .form-control height.

like image 65
jyrkim Avatar answered Oct 02 '22 00:10

jyrkim