将文本对齐到 Vuetify 中文本字段的中心

Moh*_*asi 9 html css textfield vue.js vuetify.js

我有一个显示字符串的只读文本字段。字符串应该从文本字段的左侧开始。我想知道 Vuetify 是否有办法将字符串与文本字段的中心对齐?

更新 这是我的代码:

<v-text-field
  value="Select the configuration:"
  color="grey lighten-43"
  class="text--darken-3 mt-3 text-xs-center"
  outline
  readonly
  single-line
></v-text-field>
Run Code Online (Sandbox Code Playgroud)

sam*_*ise 17

如果您使用范围样式,>>>则必须使用输入字段的深度选择器(即):

<v-text-field 
  class="centered-input text--darken-3 mt-3" 
  value="Select the configuration:" 
  color="grey lighten-43" 
  outline readonly single-line />
Run Code Online (Sandbox Code Playgroud)
<style scoped>
    .centered-input >>> input {
      text-align: center
    }
</style>
Run Code Online (Sandbox Code Playgroud)


a--*_*--m 8

文本左对齐的原因是该input集合的基类text-align: start。要解决此问题,请为该输入添加一条规则,例如:

模板:

<v-text-field 
  class="centered-input text--darken-3 mt-3" 
  value="Select the configuration:" 
  color="grey lighten-43" 
  outline readonly single-line />
Run Code Online (Sandbox Code Playgroud)

css:

<v-text-field 
  class="centered-input text--darken-3 mt-3" 
  value="Select the configuration:" 
  color="grey lighten-43" 
  outline readonly single-line />
Run Code Online (Sandbox Code Playgroud)

.centered-input input {
  text-align: center
}
Run Code Online (Sandbox Code Playgroud)
new Vue({ el: '#app' })
Run Code Online (Sandbox Code Playgroud)
.centered-input input {
  text-align: center
}
Run Code Online (Sandbox Code Playgroud)

  • 这是行不通的,而使用 &gt;&gt;&gt; 的另一个答案是 (2认同)