Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make part of the webpage not scroll with the rest of the page?

I am very new to web design, and am going to make a simple webpage. I like the idea of this webpage:

http://dropplets.com/

Where the top part doesn't scroll with the rest of the page, giving a neat scrolling effect, as well as where the very top of the scrollable part is just at the bottom of the web page (as in with one "click" of the mouse scroll wheel, you'll immediately begin to see the scrolling part). How is something such as this made possible?

like image 368
AggieDev Avatar asked Sep 04 '25 16:09

AggieDev


2 Answers

just give position:fixed; and z-index:1 to the top part which you want to back on scroll and in wrapper give position:relative; z-index:2;

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<style>
.fix-div{position:fixed; height:100%; width:100%; left:0; top:0; z-index:1;}
#wrapper{position:relative; z-index:2; margin:100% 0 0;}
</style>
</head>

<body>
    <div class="fix-div">
        Fix div content goes here...
    </div>
    <div id="wrapper">
        Your content goes here...
    </div>
</body>
</html>
like image 102
Kinjan Koradiya Avatar answered Sep 07 '25 07:09

Kinjan Koradiya


Fiddle : link

Code :

CSS :

.main{
    background-color:green;
    width:100%;
    height:100px;
    padding:0px;
    margin:0px;
    z-index:1;
    position:fixed;
    top:0px;
}

.content{
    height:1000px;
    width:100%;
    margin-top:100px;
    z-index:10;
    background-color:red;
    position:relative;
}

HTML :

<div class='main'></div>
<div class='content'></div>
like image 36
Imesh Chandrasiri Avatar answered Sep 07 '25 09:09

Imesh Chandrasiri