如何使用 JavaScript 設定元素的水平對齊方式?
要水平對齊元素,請使用 cssFloat 屬性。
示例
可以嘗試執行以下程式碼,使用 JavaScript 設定元素的水平對齊方式 −
<!DOCTYPE html>
<html>
<body>
<img id="myID" src="https://tutorialspoint.tw/videotutorials/images/tutor_connect_home.jpg" width="300" height="300">
<p>This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text.
</p>
<button type="button" onclick="display()">Align Horizontally</button>
<script>
function display() {
document.getElementById("myID").style.cssFloat = "right";
}
</script>
</body>
</html>
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP