CSS Layout How to - Vertical Alignment of Inline Elements








Question

We would like to know how to vertical Alignment of Inline Elements.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.login-button {<!--   w w w  .j  a v  a 2  s.  c o m-->
  background-color: lightgray;
  padding: 5px;
}

.loadingImg {
  padding: 0 20px;
  margin: 0 20px;
  background-color: white;
  vertical-align: middle;
}

.loginSubmit {
  vertical-align: middle;
}

.error {
  color: red;
  font-weight: bold;
  vertical-align: middle;
}
</style>
</head>
<body>
  <p class="login-button">
    <input class="loginSubmit" type="submit" value="Log On" /> 
    <img class="loadingImg" src="http://placehold.it/20x20"
      height="40" width="40" /> 
    <span class="error">text</span>
  </p>
</body>
</html>

The code above is rendered as follows: