Source Code:
(back to article)
Submit
Result:
Report an issue
<!DOCTYPE html> <html> <head> <title>Title of the document</title> <style> .parent { position: relative; width: 100%; height: 220px; background: #1faadb; color: #fff; } .child_1, .child_2 { position: absolute; top: 50%; left: 50%; width: 110px; height: 70px; background: #8ebf42; text-align: center; } .child_1 { margin: -35px 0 0 -55px; } </style> </head> <body> <div class="parent"> <div class="child_1">Vertically Centered Text</div> </div> <br/> <div class="parent"> <div class="child_2">Not Centered Text</div> </div> </body> </html>