Javascript DOM CSS Style verticalAlign Property

Introduction

Set the vertical alignment of some text in a table to "bottom":

document.getElementById("myTd").style.verticalAlign = "bottom";

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
table {/*w w  w.j av a 2  s. c o m*/
  border: 1px solid black;
  height: 100px;
}
</style>
</head>
<body>

<table>
  <tr>
    <td id="myTd">Some example text</td>
  </tr>
</table>
<br>

<button type="button" onclick="myFunction()">Align text</button>

<script>
function myFunction() {
  document.getElementById("myTd").style.verticalAlign="bottom";
}
</script>

</body>
</html>

The verticalAlign property sets or gets the vertical alignment of the content in an element.

Property Values

Value Description
length Raises or lower an element by the specified length. Negative values are allowed
% Raises or lower an element in a percent of the "line-height" property. Negative values are allowed
baselineAlign the baseline of the element with the baseline of the parent element. default
sub Aligns the element as it was subscript
super Aligns the element as it was superscript
top The top of the element is aligned with the top of the tallest element on the line
text-topThe top of the element is aligned with the top of the parent element's font
middle The element is placed in the middle of the parent element
bottom The bottom of the element is aligned with the lowest element on the line
text-bottom The bottom of the element is aligned with the bottom of the parent element's font
initial Sets this property to its default value.
inherit Inherits this property from its parent element.

The verticalAlign property returns a String representing the vertical alignment of the content in an element.




PreviousNext

Related