make a div inside a relative positioned keep position to its container when scrolling - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Relative Position

Description

make a div inside a relative positioned keep position to its container when scrolling

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
 </head> <!-- ww w  .ja  va  2 s .  com-->
 <body> 
  <div id="container" style="position:relative; width:200px; height:300px; overflow: auto;"> 
   <div style="position:absolute; top:10px; left:10px; width: 100px;"> 
    <div id="absoluteinner" style="position:fixed;  width:100px; height:100px; background-color:red;"></div> 
   </div> 
   <div id="staticinner" style="width:100px; height:800px; background-color:purple;"></div> 
  </div>  
 </body>
</html>

Related Tutorials