Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue 3 button is jumping on v-show

Can anybody advice how can I fix this jumping button?
I am using MaterializedCSS framework.

enter image description here

<h3 class="my-3">{{ name }}</h3>
    <hr />
    <transition name="fade"
      ><div v-show="isHidden">
        <span>Here I am</span>
      </div></transition
    >
    <button
      @click="isHidden = !isHidden"
      class="waves-effect waves-light btn my-8"
    >
      Click Me
    </button>

<style scoped>
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.5s;
}
.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}
</style>

I am using v-show directive so the element exists in DOM, its just hidden before button is clicked. As soon as button is clicked appeared texts moves button down.

like image 553
ussrback Avatar asked Jan 30 '26 17:01

ussrback


1 Answers

You need to put the <transition> into a container with a fixed height.

For example:
<div style="height: 50px"><transition name="fade">...</transition></div>

like image 123
tdesero Avatar answered Feb 01 '26 13:02

tdesero



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!