Horizontally & vertically centered Responsive image - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Responsive Layout

Description

Horizontally & vertically centered Responsive image

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">
html, body {
   margin:0;
   padding:0;
   width:100%;
   height:100%;
}

body {<!--from   w  w  w .  j ava2s.c om-->
   display:table;
}

.container {
   display:table-cell;
   vertical-align:middle;
   border:2px solid Chartreuse;
}

.container>div {
   width:100%;
   height:100%;
   margin:0 auto;
   border:2px solid yellow;
   max-width:551px;
   max-height:481px;
   background:url('https://www.java2s.com/style/demo/Google-Chrome.png') 51% 51% no-repeat;
   background-size:contain;
}
</style> 
 </head> 
 <body> 
  <div class="container"> 
   <div></div> 
  </div>  
 </body>
</html>

Related Tutorials