DEV Community

Trev
Trev

Posted on

2 2

A Very Nice CSS Parallax Video

This is not my video

I just thought it was really helpful so I thought I would share it here.

The props go to Red Stapler

The code involved

This CSS wrapper is dead simple and the video explains it well so I won't go into too much detail here - but if you just want to see the code involved, here it is:

HTML

    <body>
            <div class="navbar"><span>CSS Parallax Scrolling Tutorial</span></div>  
            <div class="parallax-wrapper">
                <div class="content">
                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
                       ....
                       .... 
                       Donec in justo eu ligula semper consequat sed a risus.</p>
                </div>
            </div>
            <div class="regular-wrapper">
                <div class="content">
                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
                       ....
                       .... 
                       Donec in justo eu ligula semper consequat sed a risus.</p>
                </div>
            </div>
    </body>

CSS

    html {
        overflow: hidden;
    }
    body {
        margin: 0;
        font-size: 26px;
        font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
        color: #ffffff;
        height: 100vh;
        perspective: 1px;
        transform-style: preserve-3d;
        overflow-x:hidden;
        overflow-y:auto;
    }
    .parallax-wrapper {
        width: 100vw;
        height:100vh;
        padding-top:20vh;
        box-sizing: border-box;
        transform-style: preserve-3d;
    }
    .parallax-wrapper::before {
        content:"";
        width: 100vw;
        height: 100vh;
        top:0;
        left:0;
        background-image: url("/trianglify.png");
        position: absolute;
        z-index: -1;
        transform:translateZ(-1px) scale(2);
    }
    .regular-wrapper {
        width: 100vw;
        height:100vh;
        padding-top:20vh;
        background-image: url("/trianglify2.png");
        z-index: 2;
        position: relative;
    }
    .content {
        margin: 0 auto;
        padding: 50px;
        width: 50%;
        background: #aaa;
    }

What I like about this method is that it's pure CSS and it's easy to replicate. I'm currently building a Vue component that will use this method nicely.

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay