HTML DOM 樣式 verticalAlign 屬性返回並修改 HTML 文檔中 HTML 元素內容的垂直對齊方式。
用法
以下是語法 -
返回垂直對齊
object.style.verticalAlign
修改verticalAlign
object.style.verticalAlign = “value”
值
在這裏,價值可以是 -
值 | 解釋 |
---|---|
initial | 它將此屬性值設置為其默認值。 |
inherit | 它從其父元素繼承此屬性值。 |
length | 以特定長度遞增或遞減元素。 |
percentage(%) | 它根據 line-height 屬性的百分比升高或降低元素。 |
baseline | 它將元素的基線與其父元素的基線對齊。 |
sub | 它將元素對齊為下標。 |
super | 它將元素對齊為上標。 |
top | 它將元素的頂部與行上最高的元素的頂部對齊。 |
text-top | 它將元素的頂部與父元素字體的頂部對齊。 |
middle | 它將元素對齊到父元素的中間。 |
bottom | 它將元素的底部與行上的最低元素對齊。 |
text-bottom | 它將元素的底部與父元素字體的底部對齊。 |
示例
讓我們看一個 HTML DOM 樣式 verticalAlign 屬性的例子 -
<!DOCTYPE html>
<html>
<head>
<style>
body {
color:#000;
background:lightblue;
height:100vh;
}
table {
border:2px solid #fff;
height:150px;
}
.btn {
background:#db133a;
border:none;
height:2rem;
border-radius:2px;
width:40%;
display:block;
color:#fff;
outline:none;
cursor:pointer;
margin:1rem 0;
}
</style>
</head>
<body>
<h1>DOM Style verticalAlign Property Example</h1>
<table>
<tr>
<td id="myTd">Table Data</td>
</tr>
</table>
<button onclick="add()" class="btn">Set verticalAlign</button>
<script>
function add() {
document.querySelector('td').style.verticalAlign = "top";
}
</script>
</body>
</html>
輸出
這將產生以下輸出 -
點擊 ”Set verticalAlign”按鈕調整文本的垂直對齊方式 -
相關用法
- HTML DOM Style visibility屬性用法及代碼示例
- HTML DOM Style overflowY屬性用法及代碼示例
- HTML DOM Style pageBreakAfter屬性用法及代碼示例
- HTML DOM Style transition屬性用法及代碼示例
- HTML DOM Style outlineOffset屬性用法及代碼示例
- HTML DOM Style maxWidth屬性用法及代碼示例
- HTML DOM Style textAlignLast屬性用法及代碼示例
- HTML DOM Style borderBottomWidth屬性用法及代碼示例
- HTML DOM Style width屬性用法及代碼示例
- HTML DOM Style margin屬性用法及代碼示例
- HTML DOM Style textDecoration屬性用法及代碼示例
- HTML DOM Style borderCollapse屬性用法及代碼示例
- HTML DOM Style backgroundClip屬性用法及代碼示例
- HTML DOM Style animationIterationCount屬性用法及代碼示例
- HTML DOM Style animationFillMode屬性用法及代碼示例
- HTML DOM Style pageBreakInside屬性用法及代碼示例
- HTML DOM Style paddingTop屬性用法及代碼示例
- HTML DOM Style textDecorationColor屬性用法及代碼示例
- HTML DOM Style animation屬性用法及代碼示例
- HTML DOM Style transitionDelay屬性用法及代碼示例
注:本文由純淨天空篩選整理自AmitDiwan大神的英文原創作品 HTML DOM Style verticalAlign Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。