简体   繁体   English

如何更改 vuetify 复选框标签样式?

[英]How to change vuetify checkbox label style?

Could anyone explain me how to set the css to the vuetify checkbox?谁能解释一下如何将 css 设置为 vuetify 复选框? I would like to change the font, it's size etc. but i have no idea how to access it in the style section.我想更改字体、大小等,但我不知道如何在样式部分访问它。 Here's my checkbox:这是我的复选框:

<v-checkbox
  class="type-box"
  dense
  v-for="type in feedTypeFilterList"
  :key="type.name"
  v-model="type.isSelected"
  :label="type.name"
/>

Thanks for any help.谢谢你的帮助。

I'm not sure if this is the right way to do it.我不确定这是否是正确的方法。 But with Vuetify you can also use slots.但是使用 Vuetify,您也可以使用插槽。

This way you can use add a label and style it however you want.通过这种方式,您可以使用添加标签并根据需要设置样式。

<v-checkbox>
  <template v-slot:label>
    <span id="checkboxLabel">Label Content</span>
  </template>
</v-checkbox>

<style>
#checkboxLabel {
   color: blue;
   font-size: 16px;
}
</style>

Let me know if there is anything else!让我知道是否还有其他事情!

official example for custom label自定义标签的官方示例

I think, This is more useful.我认为,这更有用。 If you want to use vue well, you have to use slot well.要想用好vue,就得用好slot。 It makes you more productive.它让你更有效率。

<div id="app">
  <v-app id="inspire">
    <v-container fluid>
      <v-checkbox v-model="checkbox">
        <template v-slot:label>
          <div>
            I agree that
            <v-tooltip bottom>
              <template v-slot:activator="{ on }">
                <a
                  target="_blank"
                  href="http://vuetifyjs.com"
                  @click.stop
                  v-on="on"
                >
                  Vuetify
                </a>
              </template>
              Opens in new window
            </v-tooltip>
            is awesome
          </div>
        </template>
      </v-checkbox>
    </v-container>
  </v-app>
</div>

<script>
new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  data () {
    return {
      checkbox: false,
    }
  },
})
</script>

Vuetify has very high specificity on the CSS, but it's quite easy to override using ::deep . Vuetify 对 CSS 具有非常高的特异性,但使用::deep很容易覆盖。

Here I've set the color and font-size to be the same for the checkbox and the label text.在这里,我将复选框和标签文本的颜色和字体大小设置为相同。 This color styling will only affect the unchecked checkbox.这种颜色样式只会影响未选中的复选框。 In order to get the white also for the checked checkbox (including the animation between states), you should add color="white" on the v-checkbox as well.为了获得选中复选框的白色(包括状态之间的动画),您还应该在v-checkbox上添加color="white"

Add checkbox in the template在模板中添加复选框

Here, color="white" controls the color of the checked checkbox, not the unchecked.在这里, color="white"控制选中复选框的颜色,而不是未选中的。

<v-checkbox
  v-model="theModel"
  color="white"
  label="This text will soon be white"
/>

Using SCSS, the styling would look like this使用 SCSS,样式看起来像这样

Using :deep overrides the vuetify styling, allowing you to create the look you want使用:deep覆盖 vuetify 样式,允许您创建所需的外观

.v-input--checkbox::v-deep {
  .v-label, .v-icon {
    color: white;
    font-size: 22px;
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM