LoginSignup
0
0

More than 5 years have passed since last update.

bootstrapでinput-groupとbtn-groupを条件によって使い分ける

Posted at

まずは、単体のinput-groupを試してみる。以下のコードで下のようなものができる。aaaaのボタンは切り替えよう。目標は、真ん中のInputFieldをボタンにかえる。

#test-area.input-group
  .input-group-btn.test-btn
    %button.btn.btn-success operator
  %input.form-control#test-input
  %button.btn.btn-info#test-set-value{style: "display: none;"} set value
  .input-group-btn.test-btn
    %button.btn.btn-success plus
%button.btn.btn-primary#change{ type: 'button' } aaaa

Screen Shot 2017-06-10 at 4.59.34 PM.png

Coffeescriptを書いて、HideしていたButtonを真ん中のInputの代わりに出すようにする。基本は、input-group, input-group-btnbtn-groupを入れ替えるだけで済む

$ ->
  $('#change').on 'click', ->
    console.log 'click'
    $('#test-input').toggle()
    $('.test-btn').toggleClass 'input-group-btn'
    $('#test-area').toggleClass 'input-group'
    $('#test-area').toggleClass 'btn-group'
    $('.test-btn').toggleClass 'btn-group'
    $('#test-set-value').toggle()

Screen Shot 2017-06-10 at 5.22.33 PM.png

このClassの付け外しを行わないと以下のように真ん中のボタンが中途半端な位置に来てしまう。

Screen Shot 2017-06-10 at 5.23.27 PM.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0