- Forums
- HTML
- How To Make A Div Show In The Center Of The Browser Screen
an example of html using css to center a div i will show you in this simple tutorial which is very basic you can put dead center a div tag [771], Last Updated: Sat May 18, 2024
wallpaperama
Sun Oct 09, 2011
1 Comments
2336 Visits
this will show a div in the dead center of the browser:
.myDiv {
position: fixed;
left: 50%;
top: 50%
overflow: auto;
margin-top: -50px;
margin-left: -100px;
background-color: #EEE;
padding: 5px;
border: 1px solid #333;
display: none;
width: 300px;
}
so here is the full code in an example i created:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Wallpaperama.com show center Div</title>
<style type="text/css">
.WallpaperamaDiv {
position: relative;
left: 50%;
top: 50%;
overflow: auto;
margin-top: -50px;
margin-left: -100px;
background-color: #EEE;
padding: 5px;
border: 1px solid #333;
width: 300px;
}
.main{
height: 700px;
width: 700px;
border: 1px solid #333;
}
</style>
</head>
<body>
<div class="main">
<h1>Wallpaperama!</h1>
<div class="WallpaperamaDiv">This box should be in the center of the browser <br />as you can see from this, it works</div>
</div>
</body>
</html>
https://www.wallpaperama.com/forums/_zyxelx.html