Bulma css 与 select2 jquery 插件

2023-12-27

我尝试实施select2 https://select2.github.io/examples.html插件使用Bulma http://bulma.io/documentation/elements/form/css框架,但前端看起来很混乱。我使用 bootstrap 尝试过,是的,没有问题,因为 select2 具有 bootstrap 兼容性。

HTML:

<div class="field">
  <label class="label">Role</label>
     <p class="control">
         <span class="select is-fullwidth">
            <select2 v-model="form.role"
                    placeholder="Select Role"
                    name="role"
                    :value="form.role"
                    :multiple="false"
             >
                <option></option>
                 <option v-for="role in roles" :value="role.id">{{ role.display_name }}</option>
         </select2>

     </span>
   </p>
</div>

我成功了,也许我的例子可以帮助你。

View

<div class="field">
    <label class="label">Hair</label>
    <div class="control">
        <select2 class="is-medium" v-model="post.custom_data.hair" :options="{}">
            @foreach (config('post.cat.hair') as $id => $value)
                <option value="{{ $id }}">{{ __($value) }}</option>
            @endforeach
        </select2>
    </div>
</div>

SASS

.select2-wrapper {
    .select2-container {
        .select2-selection {
            transition: border-color $speed;
            font-family: $family-sans-serif;
            height: 2.285em;
            line-height: 1.5;
            font-size: 1rem;
            outline: none !important;
            display: inline-flex;
            align-items: center;
            width: 100%;
            border-color: $border;
            border-radius: $radius;
            &:hover {
                border-color: $border-hover;
            }
            .select2-selection__rendered {
                padding-left: 0.75em;
                padding-right: 0.75em;
            }
            .select2-selection__arrow {
                display: none;
            }
        }

        &.select2-container--open {
            .select2-selection {
                border-color: $primary;
                &:hover {
                    border-color: $primary;
                }
            }
        }
    }

    &.is-medium {
        .select2-container {
            .select2-selection {
                font-size: $size-5;
            }
        }
    }
    &.is-large {
        .select2-container {
            .select2-selection {
                font-size: $size-4;
            }
        }
    }
}

.select2-container {
    .select2-dropdown {
        border-color: $primary;

        .select2-search {
            margin: 10px;
            .select2-search__field {
                @extend .input;
                border-radius: $radius !important;
            }
        }

        .select2-results__options {
            max-height: 210px;
            .select2-results__option {
                padding: 0.75em;
                font-family: $family-sans-serif;
                font-size: 1rem;

                &.select2-results__option--highlighted {
                    background: $primary;
                }
            }
        }
    }
}

Result

希望有帮助^^

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Bulma css 与 select2 jquery 插件 的相关文章