Absolute vertical and horizontal center text in responsive div - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Text

Description

Absolute vertical and horizontal center text in responsive div

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">
.work {<!--from   ww  w .j av  a2  s .co  m-->
   display:table;
   width:51%;
   float:left;
}

.work a {
   display:table-cell;
   vertical-align:middle;
   position:relative;
}

.work-thumb {
   width:100%;
   height:auto;
   display:block;
   margin:0;
   padding:0;
}

.work-title {
   position:absolute;
   width:100%;
   height:100%;
   top:51%;
   left:0%;
   margin:0;
   padding:0;
   display:inline-block;
   text-align:center;
   font-size:65px;
   height:65px;
   margin-top:-33px;
}
</style> 
 </head> 
 <body> 
  <article class="work"> 
   <a href="#"> <h1 class="work-title">Test title</h1> <img class="work-thumb" src="https://www.java2s.com/style/demo/Opera.png"> </a> 
  </article>  
 </body>
</html>

Related Tutorials