【问题标题】:how to change font-size of "v-text-field" in vuetify?如何在 vuetify 中更改“v-text-field”的字体大小?
【发布时间】:2021-10-27 15:24:20
【问题描述】:

我正在使用“Nuxt”应用程序并使用“Vuetify”作为我的框架。这是我的一个组件的代码:

<template>

<v-text-field
  color="var(--color4)"
  class="px-15"
>

  <template v-slot:label>

      <span class="labelClass">
          please enter your name
      </span>

  </template>

</v-text-field>

</template>

<style scoped>
.labelClass {
  font-size: 1.2rem;
}
</style>

我想增加输入中标签的字体大小。根据Vuetify ducomentation,我们必须使用“插槽”来做到这一点。所以我添加了一个新模板和“插槽”。然后我使用 labelClass 作为其中的 span 来控制字体大小。字体大小发生了变化,但这里的问题是,如果我增加字体大小(例如增加到 1.8rem),那部分文本就会消失:

如果字体大小增加,情况会变得更糟。我也阅读了this question,但它对我没有帮助。我还尝试为 v-text-field 和诸如 v-text-field__slot 之类的一些类设置“高度”属性,但它们对我不起作用。

【问题讨论】:

    标签: vue.js nuxt.js vuetify.js font-size


    【解决方案1】:

    问题是,在渲染input 后得到这个css 样式:

    .v-input input {
        max-height: 32px;
    }
    

    要解决这个问题,您只需要覆盖它。如果您不想为每个 input 覆盖它,只需向您的 v-text-field 添加另一个类:

    <v-text-field
      color="var(--color4)"
      class="px-15 my-class"
    >
    

    ...然后像这样使用它:

    .v-input.my-class input {
        max-height: 32px;
    }
    

    编辑:看起来您还需要覆盖以下样式:

    .v-input .v-label {
        height: 20px;
        line-height: 20px;
        letter-spacing: normal;
    }
    

    这是标签的样式,需要增加heightline-height。需要在以下位置完成另一个覆盖:

    .v-text-field input {
        flex: 1 1 auto;
        line-height: 30px;
        padding: 8px 0 8px;
        max-width: 100%;
        min-width: 0;
        width: 100%;
    }
    

    line-height 需要增加。

    由于你的html 在你的slot 中只显示在slotline-heightmax-width 从父母影响可见空间。

    【讨论】:

    • 你自己测试过吗?它对我不起作用。
    • @hamid-davodi 我在文档页面上对其进行了测试。渲染后请在浏览器中检查结构。
    • 我的意思是再次增加字体大小后,文本在我的应用程序中消失了,“最大高度”并没有解决我的问题。
    • 它对我不起作用,如果您测试过,请将整个组件代码放入您的答案中进行检查。
    • @hamid-davodi 可能是因为您在组件中提供了css 作为作用域。由于labelinput 将在渲染期间创建,而&lt;style scoped&gt; 仅影响现有元素,因此您需要提供全局样式。如果这仍然不能解决您的问题,请将呈现的 html 添加到您的问题中。
    猜你喜欢
    • 2023-03-21
    • 2018-08-31
    • 2021-05-13
    • 2021-08-19
    • 1970-01-01
    • 2019-11-10
    • 2020-08-22
    • 1970-01-01
    • 2018-07-14
    相关资源
    最近更新 更多