Run ยป
<!DOCTYPE html> <html> <head> <title>Title of the document</title> <style> body{ margin: 10px; font-size: 15px; } .container-2{ width: 750px; float: left; height: 400px; background-color: #ad4343; position: relative; } .container-2 .center{ width: 300px; height: 150px; background-color: #ccc; margin: auto; position: absolute; top: 0; left: 0; right: 0; bottom: 0; } </style> </head> <body> <h2>2. Center div tag with position</h2> <div class="container-2"> <div class="center"> Center box with position </div> </div> </body> </html>