I am trying to create a fixed div, so that even if i scroll down the page, the div remains in the center of the page. But I’m having a problem that some part of the div remains hidden even if scroll down the page. Please see this jsfiddle demo to see the code and the problem.
HTML:
<div class="wrap">
<div class="main">Normal div </div>
<div class="box">This should be in the slide down if page is scrolled down.</div>
</div>
CSS:
.wrap{
border: 1px solid green;
width:500px;
overflow:auto;
margin:0 auto;
}
.main{
border:1px solid blue;
width:400px;
float:right;
}
.box{
border:1px solid red;
width:85px;
top:200px;
position: fixed;
}
When an element is absolutely positioned or fixed, you can use the
topandbottomCSS properties to force the element to fill exactly the screen’s height:Or to be vertically centered on the screen:
The rule
overflow-y: autoensures that a vertical scrollbar will appear if needed, while the ruleoverflow-x: hidden;is there to prevent a horizontal scroolbar from showing up.