CSS Layout How to - Vertically Align Elements








Question

We would like to know how to vertically Align Elements.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
button {<!--from  ww  w . j av  a 2 s .  c o  m-->
  vertical-align: middle;
  height: 40px;
  display: inline-block;
}

#text {
  vertical-align: middle;
  display: inline-block;
}
</style>
</head>
<body>
  <div>
    <button type="submit" value="submit" id="button">OK</button>
    <h3 id="text">
      <a href="">Anchor</a>
    </h3>
  </div>
</body>
</html>

The code above is rendered as follows: