如何使用 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>
广告
数据结构
计算机网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言程序设计
C++
C#
MongoDB
MySQL
Javascript
PHP