HTML Element Style How to - Center full width/height








Question

We would like to know how to center full width/height.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
html {<!--   w w w  .ja v a 2 s .  c om-->
  min-height: 100%;
  height: 100%;
}

body {
  height: 100%;
  margin: 0;
}

.panel {
  background: #333;
  color: #fff;
  width: 100%;
  height: 100%;
  display: table;
}

.panel .inner {
  padding: 40px;
  text-align: center;
  display: table-cell;
  vertical-align: middle;
}
</style>
</head>
<body>
  <div class="panel">
    <div class="inner">hi there</div>
  </div>
</body>
</html>

The code above is rendered as follows: