td/th vAlign 属性
定义和用法
vAlign 属性设置或返回单元格内数据的垂直排列方式。
语法
设置 vAlign 属性:
tdObject.vAlign="baseline|bottom|middle|top"
或者
thObject.vAlign="baseline|bottom|middle|top"
返回 vAlign 属性:
tdObject.vAlign
或者
thObject.vAlign
值
|
描述
|
baseline
|
与基线对齐。
|
bottom
|
对内容进行下对齐。
|
middle
|
对内容进行下对齐。
|
top
|
对内容进行上对齐。
|
浏览器支持




所有主流浏览器都支持 vAlign 属性
实例
下面的例子更改了单元格内数据的垂直排列方式:
<html>
<head>
<script>
function displayResult()
{
document.getElementById(‘td1‘).vAlign="top";
document.getElementById(‘td2‘).vAlign="top";
document.getElementById(‘td3‘).vAlign="top";
}
</script>
</head>
<body>
<table width="50%" border="1">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Text</th>
</tr>
<tr>
<td id="td1">Peter</td>
<td id="td2">Griffin</td>
<td id="td3">Hello my name is Peter Griffin.
I need a long text for this example.
I need a long text for this example.</td>
</tr>
</table>
<br>
<button type="button" onclick="displayResult()">Top-align content</button>
</body>
</html>