Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 3 & Boostrap 4 & Bootstrap 5 - input-xs (smaller than sm)

I wasted a lot of time searching a way to make my own xs size (smaller than the small) for input and input group, so here's the code!

Peter Butkovic upload the bug/request to the bootstrap github:
https://github.com/twbs/bootstrap/issues/15107

with the following response from theirs:

We won't be adding it to v3 and I don't think we'll have the xs buttons even in v4, but I'll keep it in mind for that if we opt to keep it around.

Still working for Bootstrap 5

like image 359
Leandro Bardelli Avatar asked Apr 07 '14 18:04

Leandro Bardelli


People also ask

Can I still use Bootstrap 3?

Starting today, Bootstrap 3 will move to end of life, and will no longer receive critical security updates. Bootstrap 4 will move to Long Term Support after we release v4. 4 and will no longer receive new features from then on.

Is Bootstrap 3 or 4 better?

Bootstrap 3 used floats to handle the layout unlike flexbox in Bootstrap 4. The Flexible Box Layout makes it easier to design flexible responsive layout structure without using float or positioning. Although it has responsive features, with custom CSS the implementation has become complex with Bootstrap 4.

Is Bootstrap 3 is mobile first?

Mobile first With Bootstrap 3, we've rewritten the project to be mobile friendly from the start. Instead of adding on optional mobile styles, they're baked right into the core. In fact, Bootstrap is mobile first.

Should I learn Bootstrap 3 or 4 or 5?

Bootstrap is the latest version of Bootstrap and should be used but it mainly depends upon the code you are writing. If you are using JQuery instead of JS, then use Bootstrap 4 but if you are using JS then Bootstrap 5 should be preferred as Bootstrap 5 does not support JQuery.


2 Answers

For inputs smallers:

.input-xs {
  height: 22px;
  padding: 2px 5px;
  font-size: 12px;
  line-height: 1.5; /* If Placeholder of the input is moved up, rem/modify this. */
  border-radius: 3px;
}

Sample usage in input-group:

<div class="input-group">
    <span class="input-group-btn">
        <button class="btn btn-xs btn-success">
            <i class="glyphicon glyphicon-plus"></i>
        </button>
    </span>
    <input type="text" class="form-control input-xs" />
    <span class="input-group-btn">
        <button class="btn btn-xs btn-danger">
            <i class="glyphicon glyphicon-minus"></i>
        </button>
    </span>
</div>

Alternatively you can add class to the input-group like this one:

.input-group-xs>.form-control,
.input-group-xs>.input-group-addon,
.input-group-xs>.input-group-btn>.btn {
    height: 22px;
    padding: 1px 5px;
    font-size: 12px;
    line-height: 1.5;
}

and use:

<div class="input-group input-group-xs">
    <span class="input-group-btn">
        <button class="btn btn-success">
            <i class="glyphicon glyphicon-plus"></i>
        </button>
    </span>
    <input type="text" class="form-control" />
    <span class="input-group-btn">
        <button class="btn btn-danger">
            <i class="glyphicon glyphicon-minus"></i>
        </button>
    </span>
</div>

.input-xs {
  height: 22px!important;
  padding: 2px 5px;
  font-size: 12px;
  line-height: 1.5;
  border-radius: 3px;
}
.input-group-xs>.form-control,
.input-group-xs>.input-group-addon,
.input-group-xs>.input-group-btn>.btn {
  height: 22px;
  padding: 1px 5px;
  font-size: 12px;
  line-height: 1.5;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />

<div class="input-group">
  <span class="input-group-btn">
    <button class="btn btn-xs btn-success">
      <i class="glyphicon glyphicon-plus"></i>
    </button>
  </span>
  <input type="text" class="form-control input-xs" />
  <span class="input-group-btn">
    <button class="btn btn-xs btn-danger">
      <i class="glyphicon glyphicon-minus"></i>
    </button>
  </span>
</div>
<br/>
<div class="input-group input-group-xs">
  <span class="input-group-btn">
    <button class="btn btn-success">
      <i class="glyphicon glyphicon-plus"></i>
    </button>
  </span>
  <input type="text" class="form-control" />
  <span class="input-group-btn">
    <button class="btn btn-danger">
      <i class="glyphicon glyphicon-minus"></i>
    </button>
  </span>
</div>
like image 104
Leandro Bardelli Avatar answered Oct 20 '22 00:10

Leandro Bardelli


If you are using bootstrap-sass, then you can leverage input-size mixin:

$input-height-xs: 27px; // adjust it according to your theme.

@include input-size('.input-xs', $input-height-xs, $padding-xs-vertical, $padding-xs-horizontal, $font-size-small, $line-height-small, $input-border-radius-small);
like image 7
s.alem Avatar answered Oct 20 '22 01:10

s.alem