官术网_书友最值得收藏!

Making an input grouping

As we discussed in the last chapter, it is possible to group components together with inputs, as we did to the sign form in the home page. However, it is possible to add even more things to inputs. We will talk about some group options that can be useful.

First of all, let's exemplify the usage of grouping inputs and buttons. The main idea is almost the same—creating a div.input-group, and creating an input and a button inside this element, as shown in this HTML code:

<div class="input-group">
  <input type="text" class="form-control" placeholder="Type the page title...">
  <span class="input-group-btn">
    <button class="btn btn-success" type="button">Search</button>
  </span>
</div>

The output of the preceding code is shown in the following screenshot:

Making an input grouping

The only trick here is to add a <span> element wrapping the button. If you invert the input order with the button, you will prepend the button to the input:

<div class="input-group">
  <span class="input-group-btn">
    <button class="btn btn-success" type="button">Search</button>
  </span>
  <input type="text" class="form-control" placeholder="Type the page title...">
</div>

The output of the preceding code is shown in this screenshot:

Making an input grouping

Bootstrap also gives us the possibility to add any other kind of button. To exemplify this, let's now add a button dropdown grouped with an input. Replace <button> with the button dropdown that we just used in the previous example:

<div class="input-group">
  <span class="input-group-btn">
    <div class="btn-group pull-right">
        <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          Customer area <span class="caret"></span>
        </button>
        <ul class="dropdown-menu">
          <li><a href="#">Action</a></li>
          <li><a href="#">Another action</a></li>
          <li><a href="#">Something else here</a></li>
          <li role="separator" class="divider"></li>
          <li><a href="#">Separated link</a></li>
        </ul>
      </div>
  </span>
  <input type="text" class="form-control" placeholder="Type the page title...">
</div>

It is pretty simple; you can add almost any kind of button, prepended or appended in an input. The following screenshot shows the result of the previous HTML code:

Making an input grouping

Tip

Can you append two buttons?

This is a small challenge for you. Can you append two buttons to the same input? Try to append some more buttons to .input-group and see what happens!

主站蜘蛛池模板: 长治市| 闸北区| 龙井市| 周口市| 和硕县| 阳东县| 方山县| 康保县| 阳春市| 吉木乃县| 景泰县| 信丰县| 科尔| 穆棱市| 贵港市| 丰宁| 正镶白旗| 平原县| 阳西县| 读书| 南城县| 长葛市| 高安市| 伊春市| 麻阳| 金堂县| 汉源县| 茌平县| 宁都县| 丹阳市| 涿州市| 永平县| 溆浦县| 金华市| 宜川县| 仙游县| 黄骅市| 汝城县| 普定县| 尤溪县| 南投市|