如何使用 JavaScript 设置元素的水平对齐方式?
要水平对齐元素,请使用 cssFloat 属性。
示例
可以尝试运行以下代码,使用 JavaScript 设置元素的水平对齐方式 −
<!DOCTYPE html>
<html>
<body>
<img id="myID" src="https://tutorialspoint.com/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