<!DOCTYPE html> <html> <head> <style> body{ height:1200px; } div.outer{ width:100%; height:100%; border:1px solid black; position:relative; } div.inner{ width:60%; height:40%; border:1px solid red; position:absolute; left:20%; /* 20% = (100%-50%)/2 */ top:30%; /* 30% = (100%-40%)/2 */ } </style> </head> <body> <div class="outer"> <div class="inner"></div> </div> </body> </html>
Run
×
Share