HTML DOM verticalAlign 屬性
定義和用法
verticalAlign 屬性設(shè)置內(nèi)容在元素框中的垂直對(duì)齊方式。
語法:
Object.style.verticalAlign=value
可能的值
值 | 描述 |
---|---|
baseline | 默認(rèn)。元素放置在父元素的基線上。 |
sub | 垂直對(duì)齊文本的下標(biāo)。 |
super | 垂直對(duì)齊文本的上標(biāo) |
top | 把元素的頂端與行中最高元素的頂端對(duì)齊 |
text-top | 把元素的頂端與父元素字體的頂端對(duì)齊 |
middle | 把此元素放置在父元素的中部。 |
bottom | 把元素的頂端與行中最低的元素的頂端對(duì)齊。 |
text-bottom | 把元素的底端與父元素字體的底端對(duì)齊。 |
length | |
% | 使用 "line-height" 屬性的百分比值來排列此元素。允許使用負(fù)值。 |
實(shí)例
本例設(shè)置表格中文本的垂直對(duì)齊方式:
<html>
<head>
<script type="text/javascript">
function alignText()
{
document.getElementById("td1").style.verticalAlign="bottom";
}
</script>
</head>
<body>
<table border="1" height="100px">
<tr>
<td id="td1">
Some example text
</td>
</tr>
</table>
<br />
<input type="button" onclick="alignText()"
value="Align text" />
</body>
</html>