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: 90px; height: 90px; padding: 5px; background: #8ebf42; text-align: center; } .child_1 { transform: translate(-50%, -50%); } </style> </head> <body> <div class="parent"> <div class="child_1">Vertically Centered Box</div> </div> <br/> <div class="parent"> <div class="child_2">Not Centered Box</div> </div> </body> </html>