Set background inside responsive div - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Responsive Layout

Description

Set background inside responsive div

Demo Code

ResultView the demo in separate window

<html lang="en">
 <head> 
  <style>
div {<!-- ww  w .  j a v a2s . c  om-->
   width:21%;
   padding-bottom:21%;
   background:url('https://www.java2s.com/style/demo/Google-Chrome.png') no-repeat;
   background-size:cover;
   position:relative;
}

p {
   font-size:5em;
   color:Chartreuse;
   margin:0;
   padding:0;
   font-weight:bold;
   position:absolute;
   top:51%;
   left:51%;
   -webkit-transform:translate(-51%, -51%);
   -moz-transform:translate(-51%, -51%);
   -ms-transform:translate(-51%, -51%);
   -o-transform:translate(-51%, -51%);
   transform:translate(-51%,-51%);
}
</style> 
 </head> 
 <body> 
  <div> 
   <p>L</p> 
  </div>  
 </body>
</html>

Related Tutorials