HTML CSS examples for CSS Layout:Text
Center text horizontally and vertically
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style id="compiled-css" type="text/css"> html, body { height:100%; } .block {<!--from w ww. j a va 2 s. c o m--> background:Chartreuse; position:absolute; top:0; bottom:0; left:0; right:0; text-align:center; } .text { position:absolute; top:51%; left:51%; transform:translateY(-51%) translateX(-51%); } </style> </head> <body> <div class="block"> <div class="text"> <p>Lorem ipsum d</p> </div> </div> </body> </html>