Parent & child with position fixed, parent overflow:hidden - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Fixed Position

Description

Parent & child with position fixed, parent overflow:hidden

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <title>Lorem ipsum dolor sit amet, consectetur adipiscing el</title> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <style id="compiled-css" type="text/css">
body {<!--from  www  .  j  a v  a 2 s  .  c om-->
   font:15px arial;
}

.parent-container {
   position:relative;
   width:301px;
   height:201px;
}

.parent {
   position:absolute;
   width:301px;
   height:201px;
   background-color:Chartreuse;
   clip:rect(0, auto, auto, 0);
}

.child {
   position:fixed;
   top:51px;
   left:51px;
   padding:2em;
   background-color:yellow;
}

.child.pink {
   background-color:blue;
}
</style> 
 </head> 
 <body> 
  <div class="child pink">
    Lorem ipsum dolor sit amet 
  </div> 
  <div class="parent-container"> 
   <div class="parent"> 
    <div class="child red">
      Lorem ipsum dolor sit amet 
    </div> 
   </div> 
  </div> 
  <h1>Lorem ipsum dolor sit amet, consectetur adipiscing el</h1> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p> 
  <p>Lorem ipsum dolor sit amet, co</p>  
 </body>
</html>

Related Tutorials