0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Vuetify】レスポンシブで配置を変えたいときはtext-{breakpoint}-{value}を使う

Last updated at Posted at 2020-07-24

Vue.js + Vuetify + Firebase Project - DevMeetupをやっている際に地味に詰まったのでメモします。

やりたいこと

「EXPLOR MEETUPS」ボタン(赤)と「ORGANIZE MEETUP」ボタン(青)の配置を、ブラウザ画面の時もスマホ画面の時も中央寄せにしたい。

スクリーンショット 2020-07-24 10.03.30.png スクリーンショット 2020-07-24 10.03.35.png

何も指定しない

<template>
  <v-container>
    <v-row>
      <v-col>
        <v-btn large router to="/meetups" class="primary">Explore Meetups</v-btn>
      </v-col>
      <v-col>
        <v-btn large router to="/meetup/new" class="info">Organize Meetup</v-btn>
      </v-col>
    </v-row>
  </v-container>
</template>
スクリーンショット 2020-07-24 9.56.38.png

「EXPLOR MEETUPS」ボタンを右に寄せたら良さそうだ。

alignを指定する

<template>
  <v-container>
    <v-row>
      <!-- alignを指定 -->
      <v-col align="right"> 
        <v-btn large router to="/meetups" class="primary">Explore Meetups</v-btn>
      </v-col>
      <v-col>
        <v-btn large router to="/meetup/new" class="info">Organize Meetup</v-btn>
      </v-col>
    </v-row>
  </v-container>
</template>
スクリーンショット 2020-07-24 9.57.43.png スクリーンショット 2020-07-24 9.57.35.png

ブラウザはうまくいったが、スマホが崩れてしまった。

align, breakpointを指定する

<template>
  <v-container>
    <v-row>
      <!-- align, breakpointを指定 -->
      <v-col align="$vuetify.breakpoint.xs ? 'center' : 'right'"> 
        <v-btn large router to="/meetups" class="primary">Explore Meetups</v-btn>
      </v-col>
      <v-col>
        <v-btn large router to="/meetup/new" class="info">Organize Meetup</v-btn>
      </v-col>
    </v-row>
  </v-container>
</template>
スクリーンショット 2020-07-24 10.01.26.png

そもそも機能しなかった。

text-{breakpoint}-{value}を指定する

<template>
  <v-container>
    <v-row>
      <v-col class="text-center text-sm-right">
        <v-btn large router to="/meetups" class="primary">Explore Meetups</v-btn>
      </v-col>
      <v-col class="text-center text-sm-left">
        <v-btn large router to="/meetup/new" class="info">Organize Meetup</v-btn>
      </v-col>
    </v-row>
  </v-container>
</template>
スクリーンショット 2020-07-24 10.03.30.png スクリーンショット 2020-07-24 10.03.35.png

できました。

注意点として、

These classes can be applied to all breakpoints from xs to xl. When using a base class,.text-{value}, it is inferred to be .text-xs-${value}.

だそうで、text-xs-centerとすると機能しませんでした。

公式を見たら、いかにも文字の時のみ使う雰囲気が出てたので詰まりました。
他にもっと良い方法があれば教えてください。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?