Exercise: Add a transition to a button
A possible solution is at the end of this page.
Try it yourself
Create a small BBj file that has a button. Use CSS to make the button bigger when you hover over it, then add a transition to make the animation smoother.
As a reminder, this is the syntax of the transition:
transition: <property> <duration> <timing-function> <delay>;
Possible solution
The original course had no solution for this exercise, so this one was written for this book. It gives a BBjButton the CSS class grow-button. The hover rule scales the button and the transition smooths the change. Readers whose system asks for reduced motion get the change without the animation. The files are Exercise-ButtonTransitionComplete.bbj and Exercise-ButtonTransitionComplete.css, and you find all files in 10_AdvancedResponsive.zip.
Exercise-ButtonTransitionComplete.css
/* Exercise-ButtonTransitionComplete.css
* Styles for Exercise-ButtonTransitionComplete.bbj: a button that grows on hover.
*/
.transition-demo {
display: grid;
place-items: center;
min-height: 100%;
box-sizing: border-box;
padding: var(--dwc-space-xl);
}
/* Animate transform only. Animating width or height forces the browser to lay out the page again. */
.grow-button {
transition: transform 0.25s ease-in-out;
}
.grow-button:hover {
transform: scale(1.2);
}
/* Switch the animation off for readers who ask their system for less motion */
@media (prefers-reduced-motion: reduce) {
.grow-button {
transition: none;
}
}