Created
July 17, 2023 17:24
-
-
Save hasinhayder/1ea479f7c8536415582492ce1ceaa96f to your computer and use it in GitHub Desktop.
Hover color change dynamically in Vue.js 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script setup> | |
const themeColor = '#FFA500' | |
const style = { | |
color: themeColor | |
} | |
const buttonStyle = { | |
'--button-hover-color': themeColor | |
} | |
</script> | |
<template> | |
<section class="mx-auto container"> | |
<h2 class="text-2xl" :style="style">Hover Example</h2> | |
<button class="mt-10 bg-blue-500 text-white font-bold py-2 px-4 rounded" :style="buttonStyle"> | |
Hover Button | |
</button> | |
</section> | |
</template> | |
<style scoped> | |
button:hover{ | |
background-color: var(--button-hover-color); | |
border-color: var(--button-hover-color); | |
color:white; | |
cursor:pointer | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment