Nick
Nick

Reputation: 2034

Using VueJS and Vuetify how can I vertically and horizontally center a v-switch in v-flex?

I cannot seem to center the v-switch component inside a v-flex when elements are oriented in a row.

It feels as though I have tried all of the documented v-container, v-layout, and v-flex props on the Grid system documentation page and nothing seems to get the job done (i.e. justify-center, text-xs-center, etc).

I have tried the solutions in similar issues to no avail.

new Vue({
  el: '#app',
  data () {
    return {
      enabled: false
    }
  }
})
<head>
  <link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons" rel="stylesheet">
  <link href="https://cdn.jsdelivr.net/npm/vuetify/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>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify/dist/vuetify.js"></script>

<div id="app">
  <v-app id="inspire">
    <v-container grid-list-xl style="background: IndianRed;">
      <v-layout text-xs-center row wrap align-center style="height: 100px;">

        <v-flex xs4>
          <v-card color="success">
            Content
          </v-card>
        </v-flex>

<!–– This guy right here -->
        <v-flex xs4>
          <v-switch prepend-icon="cloud" v-model="enabled"></v-switch>
        </v-flex>

        <v-flex xs4>
          <v-card color="success">
            Content
          </v-card>
        </v-flex>

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

Upvotes: 1

Views: 6192

Answers (2)

Nick
Nick

Reputation: 2034

The solution I got to work was to use a column oriented v-layout with align-center wrapped around the v-switch component.

new Vue({
  el: '#app',
  data () {
    return {
      enabled: false
    }
  }
})
<head>
  <link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons" rel="stylesheet">
  <link href="https://cdn.jsdelivr.net/npm/vuetify/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>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify/dist/vuetify.js"></script>

<div id="app">
  <v-app id="inspire">
    <v-container grid-list-xl style="background: IndianRed;">
      <v-layout text-xs-center row wrap align-center style="height: 100px;">

        <v-flex xs4>
          <v-card color="success">
            Content
          </v-card>
        </v-flex>

<!–– This guy right here -->
        <v-flex xs4>
          <v-layout column align-center>
            <v-switch prepend-icon="cloud" v-model="enabled"></v-switch>
          </v-layout>
        </v-flex>

        <v-flex xs4>
          <v-card color="success">
            Content
          </v-card>
        </v-flex>

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

Upvotes: 1

Ohgodwhy
Ohgodwhy

Reputation: 50767

<v-flex xs4>
    <v-layout justify-center align-center>
         <v-switch prepend-icon="cloud" v-model="enabled"></v-switch>
    </v-layout>
</v-flex>

by using a nested layout with justify and align center you should get the desired effect.

Upvotes: 0

Related Questions