HTML DOM hspace 属性
JavaScript基础 2022-06-08 15:57:2316小码哥的IT人生shichen
HTML DOM hspace 属性
定义和用法
hspace 属性可设置或返回图像的左边缘和右边缘的空白。
hspace 和 vspace 属性可与 align 一同使用,来设置图像与周围文本的距离。
语法
imageObject.hspace=pixels
实例
下面的例子将设置图像的 hspace 和 vspace 属性:
<html> <head> <script type="text/javascript"> function setSpace() { document.getElementById("compman").hspace="50"
document.getElementById("compman").vspace="50" } </script> </head> <body> <img id="compman" src="compman.gif" alt="Computerman" align="right" /> <p>Some text. Some text. Some text. Some text.</p> <input type="button" onclick="setSpace()" value="Set hspace and vspace"> </body> </html>
TIY
完整实例【设置图像的水平和垂直定位】:
<html> <head> <script type="text/javascript"> function setSpace() { document.getElementById("compman").hspace="50" document.getElementById("compman").vspace="50" } </script> </head> <body> <img id="compman" src="/i/eg_compman.gif" alt="Computerman" align="right" /> <p>Some text. Some text. Some text. Some text.</p> <input type="button" onclick="setSpace()" value="Set hspace and vspace"> </body> </html>
可以使用本站在线JavaScript测试工具测试上述代码运行效果:http://www.phpcodeweb.com/runjs.html