/* Setup styles in the other file. */ div:nth-child(3) { background-color: gold; width: 66%; top: 30px; left: 30px; position: sticky; } div:nth-child(even) { position: relative; z-index: 1; }
body { font-family: sans-serif; padding: 20px; } div { background-color: deepskyblue; padding: 10px; border-top: solid black 4px; } div:not(:first-child) { margin-top: 20px; }
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="../assets/reset.css" rel="stylesheet"> <link href="setup.css" rel="stylesheet"> <link href="style.css" rel="stylesheet"> </head> <body> <section> <div> <p>This is some text in the first element.</p> </div> <div> <p>And some more in the second element.</p> </div> <div> <p>Then a third one, too.</p> </div> <div> <p>Let’s add a fourth.</p> </div> <div> <p>Even a fifth.</p> </div> <div> <p>This should let it scroll.</p> </div> <div> <p>It was the best of times; it was the worst of times.</p> </div> <div> <p>Scrolling is always fun.</p> </div> <div> <p>I guess that isn’t true.</p> </div> <div> <p>Sometimes it goes on and on, you know.</p> </div> <div> <p>Okay, this is enough.</p> </div> <div> <p>Let’s make a longer scroll on this one.</p> </div> <div> <p>To really show off the stacking.</p> </div> <div> <p>One more, for good measure.</p> </div> </section> </body> </html>