Answer a question

I'm a Beginner in Vuetify. I want to create a button on my website like this:

<v-btn class="v-btn white--text mx-1 px-6" elevation="2" x-small rounded color="#BB86FC">text</v-btn>

also am adding <v-hover> tag to my code:

<v-hover>
  <v-btn class="white--text mx-1 px-6" elevation="2" x-small rounded color="#BB86FC">text</v-btn>
</v-hover>

and adding style in my CSS:

.v-btn:hover:

but is not working.

How can I give it a different style to change the background color so when hovering over the button, the color changes to "red"?

Answers

You can add v-slot on v-hover and use it in the style-binding of the button as follows:

new Vue({ el:"#app", vuetify: new Vuetify() });
<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><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@4.x/css/materialdesignicons.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.css" rel="stylesheet">

<v-app id="app">
   <v-hover v-slot="{ hover }">
     <v-btn 
       class="v-btn white--text mx-1 px-6"
       elevation="2" 
       x-small 
       rounded
       :style="{ 'background-color': hover ? 'red' : '#BB86FC' }"
     >text</v-btn>
   </v-hover>
</v-app>
Logo

前往低代码交流专区

更多推荐