Position:absolute + left:50% = max-width:50% - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Absolute Position

Description

Position:absolute + left:50% = max-width:50%

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">
.box {<!--from  ww  w  .  j  a v a 2s. co  m-->
   position:absolute;
   width:auto;
   display:table;
   max-width:76%;
   left:0;
   right:0;
   background:Chartreuse;
   color:yellow;
   margin:auto;
}

.box1 {
   top:21px;
}

.box2 {
   top:100px;
}
</style> 
 </head> 
 <body> 
  <div class="box box1">
    Lorem ipsum dolor sit amet, c 
  </div> 
  <div class="box box2">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi ullamcorper molestie lacus sed fermentum. Aliquam erat volutpat. Vestibulum tortor neque, ornare vitae tempor hendrerit, luctus at neque. Phasellus sed quam pharetra, tincidunt tortor in, pharetra nisl. Maecenas aliquam luctus mauris, vitae venenatis diam imperdiet vel. Donec tortor 
  </div>  
 </body>
</html>

Related Tutorials