Home > Web Front-end > CSS Tutorial > How to Build a CSS Slide-In Transition from the Left?

How to Build a CSS Slide-In Transition from the Left?

Barbara Streisand
Release: 2024-12-15 06:11:13
Original
633 people have browsed it

How to Build a CSS Slide-In Transition from the Left?

How to Create a CSS Slide-in Transition from the Left

In CSS, achieving a slide-in transition from the left involves leveraging either CSS3 transitions or animations. Here's how you can implement it:

Using CSS3 Transitions with Hover (Demo One)

.wrapper:hover #slide {
    transition: 1s;
    left: 0;
}
Copy after login

This snippet smoothly transitions the element's position from left: -100px; to 0 over 1 second on hover. You can also utilize transform: translate() to adjust the element's position.

Using CSS3 Animations (Demo Two)

#slide {
    position: absolute;
    left: -100px;
    width: 100px;
    height: 100px;
    background: blue;
    -webkit-animation: slide 0.5s forwards;
    -webkit-animation-delay: 2s;
    animation: slide 0.5s forwards;
    animation-delay: 2s;
}

@-webkit-keyframes slide {
    100% { left: 0; }
}

@keyframes slide {
    100% { left: 0; }
}
Copy after login

Similar to the previous example, this animation automatically initiates after 2 seconds with the animation-delay property. Setting animation-fill-mode to forwards preserves the element's visibility after the animation concludes.

Browser Support

Refer to caniuse.com for detailed information on browser compatibility for CSS transitions and animations.

Further Reading

For more in-depth knowledge on these techniques, explore:

  • CSS Animations: https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Using_CSS_animations
  • CSS Transitions: https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Using_CSS_transitions

The above is the detailed content of How to Build a CSS Slide-In Transition from the Left?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template