We would like to know how to center div horizontally and vertically.
<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.wraptocenter {<!--from w w w . ja v a2s . c om-->
display: table-cell;
text-align: center;
vertical-align: middle;
width: 200px;
height: 200px;
background-color: #999;
}
.wraptocenter * {
vertical-align: middle;
}
.wraptocenter {
display: block;
}
.wraptocenter span {
display: inline-block;
height: 100%;
width: 1px;
}
</style>
</head>
<body>
<div class="wraptocenter">
<span></span><img src="http://www.java2s.com/style/download.png"
alt="...">
</div>
</body>
</html>
The code above is rendered as follows: