如何减小Vuetify输入控件中标签和字段之间的间距?

huangapple go评论63阅读模式
英文:

How to lower space between label and field for Vuetify input controls?

问题

以下是已翻译的内容:

给定一个自定义的 Vuetify 文本字段示例

<template>
  <v-app>
    <v-container>
      <v-text-field
        label="标签在这里"
        variant="plain"
        density="compact"
        hide-details="auto"
        color="primary"
        class="my-1"
        model-value="这里放一些文本"
      />
    </v-container>
  </v-app>
</template>
<style scoped>
  :deep(.v-input),
  :deep(.v-field),
  :deep(.v-label--clickable) {
    font-size: 12px;
  }

  :deep(.v-label.v-field-label) {
    font-size: 10px;
  }
</style>

标签和内容之间的垂直间距太大。

如何减小Vuetify输入控件中标签和字段之间的间距?

降低间距的最佳方法是什么?我尝试添加以下样式:

.v-input {
  height: 4px;
  min-height: 4px;
  max-height: 4px;
}

.v-field {
  height: 4px;
  min-height: 4px;
  max-height: 4px;
}

.v-text-field {
  height: 4px;
  min-height: 4px;
  max-height: 4px;
}

但没有任何变化。

英文:

Given a customized Vuetify textfield as an example

(Playground)

&lt;template&gt;
  &lt;v-app&gt;
    &lt;v-container&gt;
      &lt;v-text-field
        label=&quot;label goes here&quot;
        variant=&quot;plain&quot;
        density=&quot;compact&quot;
        hide-details=&quot;auto&quot;
        color=&quot;primary&quot;
        class=&quot;my-1&quot;
        model-value=&quot;some text goes here&quot;
      /&gt;
    &lt;/v-container&gt;
  &lt;/v-app&gt;
&lt;/template&gt;

&lt;style scoped&gt;
  :deep(.v-input),
  :deep(.v-field),
  :deep(.v-label--clickable) {
    font-size: 12px;
  }

  :deep(.v-label.v-field-label) {
    font-size: 10px;
  }
&lt;/style&gt;

The vertical space between the label and the content is too much

如何减小Vuetify输入控件中标签和字段之间的间距?

What is the best way to lower the space? I tried to add

  .v-input {
    height: 4px;
    min-height: 4px;
    max-height: 4px;
  }

  .v-field {
    height: 4px;
    min-height: 4px;
    max-height: 4px;
  }

  .v-text-field {
    height: 4px;
    min-height: 4px;
    max-height: 4px;
  }

to see what happens but nothing changed.

答案1

得分: 1

标签在Y轴上偏移。在遇到这种问题时,始终使用浏览器开发者工具来识别您不理解其位置的元素,找出"为什么它在那里"。查找不相关的设置和修改,调整它们将产生所需的结果。

影响元素位置的因素:

  • 通常是position,带有topbottomleftright(相对于另一个元素的位置变化)
  • marginpaddingborder(开发者工具指示这些)
  • 较少频繁的是变换(translateX()translateY()translateZ()

解决方案(标签变换过高):

.v-field--variant-plain .v-label.v-field-label--floating {
  transform: translate(0px);
}

Vuetify Playground

如何减小Vuetify输入控件中标签和字段之间的间距?

英文:

The label is shifted on the Y-axis. When encountering such an issue, always use browser developer tools to identify the element whose position you don't understand, to find out "why it is there." Look for irrelevant settings and modifications that, when adjusted, will yield the desired result.

Factors influencing element position:

  • generally position, with top, bottom, left, right (position changes relative to another element)
  • margin, padding, border (developer tools indicate these)
  • less frequently, transformations (translateX(), translateY(), translateZ())

Solution (label transform too high)

.v-field--variant-plain .v-label.v-field-label--floating {
  transform: translate(0px);
}

Vuetify Playground

如何减小Vuetify输入控件中标签和字段之间的间距?

huangapple
  • 本文由 发表于 2023年6月15日 18:26:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76481570.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定