0
0
Vueframework~20 mins

CSS transition classes in Vue - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
CSS Transition Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when a Vue component uses with CSS classes?

Consider a Vue 3 component that wraps an element with a <transition> tag and uses CSS classes for enter and leave animations. What is the visible behavior when the element is toggled?

Vue
<template>
  <transition name="fade">
    <p v-if="show">Hello!</p>
  </transition>
</template>

<script setup>
import { ref } from 'vue'
const show = ref(true)
</script>

<style>
.fade-enter-active, .fade-leave-active {
  transition: opacity 0.5s ease;
}
.fade-enter-from, .fade-leave-to {
  opacity: 0;
}
.fade-enter-to, .fade-leave-from {
  opacity: 1;
}
</style>
AThe paragraph smoothly fades in and out by changing opacity when toggled.
BThe paragraph slides in from the left when shown and slides out to the right when hidden.
CThe paragraph instantly appears and disappears without any animation.
DThe paragraph changes color but does not fade in or out.
Attempts:
2 left
💡 Hint

Look at the CSS classes and their effects on opacity and transition properties.

📝 Syntax
intermediate
1:30remaining
Which CSS class name is correct for Vue transition enter active state?

Vue transition classes follow a naming pattern based on the transition name. If the transition name is slide, which CSS class targets the enter active state?

A.slide-entering-active
B.slide-enter-active
C.slide-enter-active-state
D.slide-enter-active-class
Attempts:
2 left
💡 Hint

Vue uses a fixed naming pattern for transition classes.

🔧 Debug
advanced
2:30remaining
Why does the Vue transition not animate the element?

This Vue component uses a <transition> with CSS classes, but the element appears and disappears instantly without animation. What is the likely cause?

Vue
<template>
  <transition name="fade">
    <div v-if="visible">Content</div>
  </transition>
</template>

<script setup>
import { ref } from 'vue'
const visible = ref(true)
</script>

<style>
.fade-enter-active, .fade-leave-active {
  transition: opacity 1s ease;
}
.fade-enter-from, .fade-leave-to {
  opacity: 0;
}
.fade-enter-to, .fade-leave-from {
  opacity: 1;
}
</style>
AThe CSS classes use incorrect names; they should be 'fade-enter-from' and 'fade-leave-from' instead of 'fade-enter' and 'fade-leave'.
BThe transition name 'fade' is not defined in the component's script.
CThe 'v-if' directive is missing a key attribute on the element.
DThe transition duration is too short to notice the animation.
Attempts:
2 left
💡 Hint

Check the official Vue 3 transition class naming conventions.

state_output
advanced
2:00remaining
What is the final opacity of the element after transition ends?

Given this Vue transition with CSS classes, what is the opacity of the element after the enter transition finishes?

Vue
<template>
  <transition name="fade">
    <span v-if="show">Text</span>
  </transition>
</template>

<script setup>
import { ref } from 'vue'
const show = ref(true)
</script>

<style>
.fade-enter-active, .fade-leave-active {
  transition: opacity 0.3s ease-in-out;
}
.fade-enter-from, .fade-leave-to {
  opacity: 0;
}
.fade-enter-to, .fade-leave-from {
  opacity: 1;
}
</style>
AOpacity oscillates between 0 and 1 indefinitely.
BOpacity is 0 (fully transparent) after the enter transition ends.
COpacity is 1 (fully visible) after the enter transition ends.
DOpacity remains at 0.5 after the transition ends.
Attempts:
2 left
💡 Hint

Look at the fade-enter-to class opacity value.

🧠 Conceptual
expert
1:30remaining
Which Vue transition class controls the element's style during the leave phase start?

In Vue 3's CSS transition system, which class is applied to the element at the start of the leave phase to define its initial style?

Aname-leave-start
Bname-leave-active
Cname-leave-to
Dname-leave-from
Attempts:
2 left
💡 Hint

Think about the naming pattern for the leave phase start state.