如何使用 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>
廣告
資料結構
計算機網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP