Position element absolute relative to 100% width parent - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Relative Position

Description

Position element absolute relative to 100% width parent

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <style id="compiled-css" type="text/css">
.navigation {<!-- ww  w . ja va2  s . co  m-->
   width:501px;
   background:Chartreuse;
   margin:0 auto;
   text-align:center;
   padding:6px 0;
   margin-bottom:11px;
}

.navigation ul {
   list-style-type:none;
   padding:0;
}

.navigation ul li {
   display:inline;
   padding-right:21px;
}

.grandParent {
   position:relative;
   width:100%;
}

.parent {
   background:url('https://www.java2s.com/style/demo/Google-Chrome.png') no-repeat 0 21%;
   background-size:cover;
   height:301px;
}

.child h1 {
   position:absolute;
   top:26%;
   left:26%;
   color:yellow;
   font-size:61px;
   font-weight:bold;
   width:51%;
   text-align:center;
}

.child .box {
   position:absolute;
   bottom:-11px;
   right:51%;
   margin-right:-251px;
   background:blue;
   padding:11px 26px;
   color:pink;
   font-size:21px;
   z-index:11;
   display:block;
}
</style> 
 </head> 
 <body> 
  <div class="navigation"> 
   <ul> 
    <li>Lorem </li> 
    <li>Lorem i</li> 
    <li>Lorem i</li> 
   </ul> 
  </div> 
  <div class="grandParent"> 
   <div class="parent"> 
    <div class="child"> 
     <h1>Lorem ipsum</h1> 
     <div class="box">
       Lorem ipsum dolor sit amet, consectetur adip 
     </div> 
    </div> 
   </div> 
  </div>  
 </body>
</html>

Related Tutorials