Vuetify右对齐一组按钮

13

我有一组按钮,希望它们位于页面的右侧,但是v-row上的justify-end/justify='end'不起作用。

<!DOCTYPE html>
<html>

<head>
  <link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
  <link href="https://cdn.jsdelivr.net/npm/@mdi/font@3.x/css/materialdesignicons.min.css" rel="stylesheet">
  <link href="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.css" rel="stylesheet">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
</head>

<body>
  <div id="app">
    <v-app>
      <v-container>
        <v-form>
          <v-row justify='end'>
            <v-col>
              <v-btn>Button 1</v-btn>
              <v-btn>Button 1</v-btn>
              <v-btn>Button 1</v-btn>
            </v-col>
          </v-row>
        </v-form>
      </v-container>
    </v-app>
  </div>

  <script src="https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.js"></script>
  <script>
    new Vue({
      el: '#app',
      vuetify: new Vuetify(),
    })
  </script>
</body>

我看过这个问题,但是使用文本对齐似乎很hacky,我想知道是否有更好的解决方案?


尝试将具有 justify='end' 的 v-row 放置在 v-col 中。 - Tom Berghuis
3个回答

40
<v-col> 添加 text-right 类:
<v-col class="text-right">
  <v-btn>Button 1</v-btn>
  <v-btn>Button 2</v-btn>
  <v-btn>Button 3</v-btn>
</v-col>

1
<v-btn :right="true" :absolute="true"></v-btn> - Ben Summerhayes
1
@BenSummerhayes 很遗憾,你的提示在 Vuetify 3.1.3 中对我无效。 - ShadowGames

8
不更改网格系统的情况下,尝试添加<spacer/>组件,以便将v-col放在行的末尾,如下所示:

<!DOCTYPE html>
<html>

<head>
  <link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
  <link href="https://cdn.jsdelivr.net/npm/@mdi/font@3.x/css/materialdesignicons.min.css" rel="stylesheet">
  <link href="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.css" rel="stylesheet">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
</head>

<body>
  <div id="app">
    <v-app>
      <v-container tag="div">

        <v-form>
          <v-row justify="end">
            <spacer/>
            <v-col>
              <v-btn>Button 1</v-btn>
              <v-btn>Button 1</v-btn>
              <v-btn>Button 1</v-btn>
            </v-col>
          </v-row>
        </v-form>

      </v-container>
    </v-app>
  </div>

  <script src="https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.js"></script>
  <script>
    new Vue({
      el: '#app',
      vuetify: new Vuetify(),
    })
  </script>
</body>


1

在一个v-row的类中使用justify-end才能使其正常工作,不能在v-col上使用。文档:https://vuetifyjs.com/en/api/v-row/根据您放置它们的位置,您可能需要调整间距,但您可以使用该类来避免任何样式问题。

    <v-form>
     <v-row class="justify-end">
       <v-btn class="mr-2">Button 1</v-btn>
       <v-btn class="mr-2">Button 1</v-btn>
       <v-btn class="mr-2">Button 1</v-btn>
     </v-row>
    </v-form>

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