Bulma CSS与Select2 jQuery插件配合使用

6
我尝试使用Bulma CSS框架来实现select2插件,但前端看起来很混乱。我尝试使用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>
2个回答

7
我已经让它工作了,也许我的例子可以帮助你。 视图
<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;
                }
            }
        }
    }
}

结果

enter image description here

希望这有所帮助 ^^


谢谢@josec89,我可以问一下你把这个Sass文件放在哪里了吗? - YouneL
1
嗨@younel,我将那个Sass文件放在了我的项目结构中(我想我称它为components/select2.scss,但这并不重要)。顺便说一下,我使用了一些在Bulma的Sass文件中定义的变量(例如$primary),还可能有其他仅在我的代码中有效的变量,请在您的样式无法编译时删除它们。 - josec89
1
我已经修复了这个问题,针对Bulma的最新版本进行了操作,通过隐藏下拉箭头来解决(因为Bulma在元素上已经添加了自己的箭头)。 - DisgruntledGoat

2
.select2-container {
  .select2-selection--single {
    height: auto !important;
    padding: 3px 0 !important;
    border: 1px solid #dbdbdb !important;

    .select2-selection__arrow{
      top: 5px !important;
    }

    .select2-selection__placeholder {
      color: #dbdbdb !important;
    }
  }

  .select2-dropdown {
    border: 1px solid #dbdbdb !important;
    border-top: 0 !important;

    .select2-search {
      margin: 5px;

      .select2-search__field {
        padding: 10px !important;
        border-radius: 3px !important;
        font-size: 1rem;
        height: 2.25em;
        box-shadow: inset 0 1px 2px rgba(10,10,10,.1);
        max-width: 100%;
        width: 100%;
        border-radius: 3px !important;
      }
    }

    .select2-results__options {
      max-height: 200px !important;

      .select2-results__option {
        padding: 0.37em 0.75em !important;
        font-size: 1rem;

        &.select2-results__option--highlighted {
        }
      }
    }
  }
}

这里输入图片描述

我就此提出了问题。

https://github.com/jgthms/bulma/issues/1555


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接