Make <div> scale to content when absolutely positioned - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Absolute Position

Description

Make <div> scale to content when absolutely positioned

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">
div {<!--from   w w  w .j  ava  2s.  c o  m-->
   position:absolute;
   background:red;
}

p {
   width:100px;
   background:blue;
   text-align:center;
}
</style> 
 </head> 
 <body> 
  <div> 
   <p>Lorem ipsum</p> 
  </div>  
 </body>
</html>

Related Tutorials