๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Lect & Tip/bootstrap

๋ถ€ํŠธ์ŠคํŠธ๋žฉ ์…€๋ ‰ํŠธ .bootstrap-select css ์Šคํƒ€์ผ ๋ณ€๊ฒฝ ๋ชจ๋‘ ์„ ํƒ ํ•ด์ œ ํ† ๊ธ€ ๋ฒ„ํŠผ scss

by ๋‚ฏ์„ ๊ณต๊ฐ„2019 2019. 11. 14.

๋ชฉ์ฐจ

    ๋ถ€ํŠธ์ŠคํŠธ๋žฉ ์…€๋ ‰ํŠธ .bootstrap-select css ์Šคํƒ€์ผ ๋ณ€๊ฒฝ

    ๋ถ€ํŠธ์ŠคํŠธ๋žฉ์˜ ์…€๋ ‰ํŠธ๋Š” ์…€๋ ‰ํŠธ ๊ทธ ์ž์ฒด๋Š” ์˜ˆ์˜์ง€๋งŒ, ๋ฉ€ํ‹ฐ ์…€๋ ‰ํŠธ ์‚ฌ์šฉ ์‹œ์— ์„ ํƒ ์ฒดํฌ๊ฐ€ ๋„ˆ๋ฌด ์•ˆ ์˜ˆ์˜๋‹ค.

    ๋”๋”๊ตฐ๋‹ค๋‚˜ ํ•œ๊ตญ์‚ฌ๋žŒ๋“ค์€ ๋ฉ€ํ‹ฐ ์…€๋ ‰ํŠธ์— ์ต์ˆ™ํ•˜์ง€ ์•Š์•„์„œ checkbox๋ฅผ ํ•„์š”๋กœ ํ•œ๋‹ค.

    ์œ„์™€ ๊ฐ™์€ ๋ฉ€ํ‹ฐ ์…€๋ ‰ํŠธ ๋ฐ•์Šค๋ฅผ ์ •๋ง ์•ˆ ์˜ˆ์˜๋‹ค.

    ์ด๊ฒƒ์„ ๋งˆ์น˜ ์ฒดํฌ๋ฐ•์Šค๋กœ ์„ ํƒํ•œ ๊ฒƒ์ฒ˜๋Ÿผ ๋ฐ”๊พธ๋Š” ๊น€์— ๋ชจ๋‘ ์„ ํƒ๊ณผ ๋ชจ๋‘ ํ•ด์ œ ๋ฒ„ํŠผ๋„ ๋งˆ์น˜ ์ „์ฒด ์„ ํƒ ์ฒดํฌ๋ฐ•์Šค์ธ ๊ฒƒ์ฒ˜๋Ÿผ ๋ฐ”๊ฟ”๋ณด์ž.

    ๋ฌผ๋ก  ์ด๋•Œ ์ฒดํฌ๋ฐ•์Šค๋Š” ์ด๋ฏธ์ง€ BG๋‹ค.

    ์ด ๋ฐฉ์‹์„ ์“ธ ๋•Œ์˜ ๊ฐœ๋ฐœ ์ด์ ์€ ๋ชจ๋‘ ์„ ํƒ๊ณผ ํ•ด์ œํ•  ๋•Œ ์ „์ฒด ์ฒดํฌ๋ฐ•์Šค์˜ checked๋ฅผ ์ œ์–ดํ•ด์ค„ ํ•„์š”๊ฐ€ ์—†๋‹ค.

    bootstrap ์ž์ฒด์˜ jquery๊ฐ€ ๊ธฐ๋ณธ์ ์œผ๋กœ ๋ฐ˜์ „ํ•ด ์ค€๋‹ค.

    ๋ถ€ํŠธ์ŠคํŠธ๋žฉ ์…€๋ ‰ํŠธ์— multiple์„ ์ค„ ๋•Œ data-actions-box="true"๋ฅผ ํ™œ์„ฑํ™”์‹œ์ผœ์„œ bs-actionsbox๊ฐ€ ์กด์žฌํ•  ๋•Œ ํ˜•์ œ ์ธ์ ‘ ์„ ํƒ์ž๋กœ ๋ฉ€ํ‹ฐ ์…€๋ ‰ํŠธ ์œ ๋ฌด๋ฅผ ํŒ๋‹จํ•ด์„œ ์Šคํƒ€์ผ์„ ๋ฐ”๊พผ๋‹ค.

    data-actions-box="true"๋ฅผ ์“ฐ์ง€ ์•Š์œผ๋ฉด ๊ทธ๋ƒฅ ํ‰๋ฒ”ํ•œ ๋ถ€ํŠธ์ŠคํŠธ๋žฉ ์…€๋ ‰ํŠธ ๋ฐ•์Šค๋กœ ๋ณด์ด๋„๋ก ํ–ˆ๋‹ค.

    html

    <select multiple data-actions-box="true" class="form-control selectpicker noborder"
    data-width="100px" title="๊ฒ€์ƒ‰๊ตฌ๋ถ„">
    <option>์ œ๋ชฉ</option>
    <option>ํฌ์ŠคํŠธ๋‚ด์šฉ</option>
    <option>ํƒœ๊ทธ</option>
    <option>๋“ฑ๋ก์ž</option>
    <option>์ˆ˜์ •์ž</option>
    </select></li>

    SCSS

    .bootstrap-select {
      .bs-actionsbox {
        padding: 0;
    
        & button {
    
          &:hover,
          &:focus {
            background: #ccc url(/assets/images/bg/chkbox_on.png) 1.5rem center no-repeat !important;
          }
        }
      }
    
      & button {
    
        &:not(.bs-placeholder)+.dropdown-menu {
          & .bs-select-all {
            display: none;
          }
    
          & .bs-deselect-all {
            text-align: left;
            padding: 0.25rem 0.5rem 0.25rem 3.5rem;
            width: 100%;
            background: url(/assets/images/bg/chkbox_on.png) 1.5rem center no-repeat;
          }
        }
    
        &.bs-placeholder+.dropdown-menu {
          & .bs-deselect-all {
            display: none;
          }
    
          & .bs-select-all {
            text-align: left;
            padding: 0.25rem 0.5rem 0.25rem 3.5rem;
            width: 100%;
            background: #fff url(/assets/images/bg/chkbox.png) 1.5rem center no-repeat;
          }
        }
      }
    
    
      & .bs-actionsbox+.inner ul.dropdown-menu li {
        & a:not(.selected) {
          & span.check-mark {
            display: inline-block;
            margin-right: 5px;
    
            &:after {
              background: #fff url(/assets/images/bg/chkbox.png) left center no-repeat;
              border: 0 none;
              transform: rotate(0deg);
              width: 18px;
              height: 18px;
              border-radius: 2px;
            }
          }
        }
    
        & a.selected {
          & span.check-mark {
            position: relative !important;
            display: inline-block !important;
            margin-right: 5px;
            top: auto !important;
            right: auto !important;
    
            &:after {
              background: #fff url(/assets/images/bg/chkbox_on.png) left center no-repeat;
              border: 0 none;
              transform: rotate(0deg);
              width: 18px;
              height: 18px;
              border-radius: 2px;
            }
          }
        }
      }
    }

    CSS

    
    .bootstrap-select .bs-actionsbox {
      padding: 0;
    }
    
    .bootstrap-select .bs-actionsbox button:hover, .bootstrap-select .bs-actionsbox button:focus {
      background: #ccc url(/assets/images/bg/chkbox_on.png) 1.5rem center no-repeat !important;
    }
    
    .bootstrap-select button:not(.bs-placeholder) + .dropdown-menu .bs-select-all {
      display: none;
    }
    
    .bootstrap-select button:not(.bs-placeholder) + .dropdown-menu .bs-deselect-all {
      text-align: left;
            padding: 0.25rem 0.5rem 0.25rem 3.5rem;
      width: 100%;
      background: url(/assets/images/bg/chkbox_on.png) 1.5rem center no-repeat;
    }
    
    .bootstrap-select button.bs-placeholder + .dropdown-menu .bs-deselect-all {
      display: none;
    }
    
    .bootstrap-select button.bs-placeholder + .dropdown-menu .bs-select-all {
      text-align: left;
            padding: 0.25rem 0.5rem 0.25rem 3.5rem;
      width: 100%;
      background: #fff url(/assets/images/bg/chkbox.png) 1.5rem center no-repeat;
    }
    
    .bootstrap-select .bs-actionsbox + .inner ul.dropdown-menu li a:not(.selected) span.check-mark {
      display: inline-block;
      margin-right: 5px;
    }
    
    .bootstrap-select .bs-actionsbox + .inner ul.dropdown-menu li a:not(.selected) span.check-mark:after {
      background: #fff url(/assets/images/bg/chkbox.png) left center no-repeat;
      border: 0 none;
      -webkit-transform: rotate(0deg);
              transform: rotate(0deg);
      width: 18px;
      height: 18px;
      border-radius: 2px;
    }
    
    .bootstrap-select .bs-actionsbox + .inner ul.dropdown-menu li a.selected span.check-mark {
      position: relative !important;
      display: inline-block !important;
      margin-right: 5px;
      top: auto !important;
      right: auto !important;
    }
    
    .bootstrap-select .bs-actionsbox + .inner ul.dropdown-menu li a.selected span.check-mark:after {
      background: #fff url(/assets/images/bg/chkbox_on.png) left center no-repeat;
      border: 0 none;
      -webkit-transform: rotate(0deg);
              transform: rotate(0deg);
      width: 18px;
      height: 18px;
      border-radius: 2px;
    }

    ๋ฐ˜์‘ํ˜•

    ๋Œ“๊ธ€