Vertically and horizontally aligning text over an image of variable size - HTML CSS CSS Widget

HTML CSS examples for CSS Widget:Image Text Alignment

Description

Vertically and horizontally aligning text over an image of variable size

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">
.image-with-label
 {
   display:inline-block;
   position:relative;
}

.image-with-label>div
 {
   position:absolute;
   top:0px;
   right:0px;
   bottom:0px;
   left:0px;
}

.image-with-label>div table
 {
   width:100%;
   height:100%;
   text-align:center;
   vertical-align:middle;<!--   ww  w  . j a va2s  .  com-->
}

.image-with-label>div table div
 {
   display:inline-block;
   background-color:Chartreuse;
   padding:6px;
}
</style> 
 </head> 
 <body> 
  <div class="image-with-label"> 
   <img src="https://www.java2s.com/style/demo/Firefox.png"> 
   <div> 
    <table> 
     <tbody> 
      <tr> 
       <td> 
        <div>
          Lorem ipsum dolor s 
        </div> </td> 
      </tr> 
     </tbody> 
    </table> 
   </div> 
  </div> 
  <div class="image-with-label"> 
   <img src="https://www.java2s.com/style/demo/Opera.png"> 
   <div> 
    <table> 
     <tbody> 
      <tr> 
       <td> 
        <div>
          Lorem ipsum dolor s 
        </div> </td> 
      </tr> 
     </tbody> 
    </table> 
   </div> 
  </div> 
  <div class="image-with-label"> 
   <img src="https://www.java2s.com/style/demo/Opera.png"> 
   <div> 
    <table> 
     <tbody> 
      <tr> 
       <td> 
        <div>
          Lorem ipsum dolor s 
        </div> </td> 
      </tr> 
     </tbody> 
    </table> 
   </div> 
  </div>  
 </body>
</html>

Related Tutorials