tags:

views:

31

answers:

2

I'm trying to create a scrolling effect in pure CSS where "pages" emerge/slide over each other instead of moving in and out the screen as usually.

My intention was to have a parent element which is position relative and overflow scroll. Inside of that are "windows" containing a "page". The windows have overflow hidden, and the pages are positioned absolutely at the top of the parent, and have the same size.

If this would work as expected, you would only be able to see a page when its window is in view.

In reality, I just see all the pages at the same time, ignoring their parent's overflow hidden property, while they are way outside of its boundaries.

I've seen this effect in the wild once, but I can't remember where and how. Anyone know how it's done?

The html:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Newspaper Scroll Test</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    <link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
    <div id="content">
        <div class="post">
            <h3>Test</h3>
            <div>
            lorem ipsum dolor sit amet.
            </div>
        </div>
        <div class="post">
            <h3>Test</h3>
            <div>
            aap noot mies.
            </div>
        </div>
        <div class="post">
            <h3>Testje</h3>
            <div>
            fietspomp
            </div>
        </div>
        <div class="post">
            <h3>ttpttp</h3>
            <div>
            lorem ipsum dolor sit amet.
            </div>
        </div>
    </div>
</body>
</html>

the css:

#content {
height: 200px;
width: 200px;
overflow: auto;
position: relative;
}

.post {
overflow: hidden;
height: 200px;
}

.post div {
position: absolute;
top: 50px;
left: 0;
}

.post h3 {
position: absolute;
top: 0;
left: 0;
}
A: 

I believe this is the effect you're going for. The changes I've made to your CSS are primarily in the .post class:

.post {
    overflow: hidden; 

    position: absolute;
    z-index: 1;
    top: 50px;
    left: 0;

    height: 200px;
    background: #fff;
}

Instead of setting the nested .post div to position absolute, I've set the entire .post as absolute. This way you can stack each of your content posts. I also added a background colour so that posts wouldn't show through each other.

To get a different page to show, you just need to change it's z-index to a higher value than 1.

Alternatively, if you want a scrolling effect with the posts stacked one after the other, you can change the CSS as follows:

.post {
    overflow: hidden;    
    height: 200px;
    background: #fff;
}
Pat
Not at all what I want. This just creates a stack of posts. What I want is very complex to explain in words. It's sort of a stack of posts of which only one at a time is shown, through its window. That is why post is not positioned and has an overflow hidden. .post will scroll down, and reveal it's inner(positioned) parts as they slide into view.
Pepijn
A: 

Not at all what I want. This just creates a stack of posts. What I want is very complex to explain in words.

Pepjin, Is this what you are trying to do?

websea
Not exactly. The best way to understand what I mean is probably to realize I know CSS quite well, and my example would work, if only overflow: hidden; would work on absolutely positioned elements. The overflow hidden should prevent any element from being displayed unless .post is overlapping with its children.
Pepijn