HTML DOM borderWidth 属性

定义和用法

borderWidth 属性设置所有四个边框的宽度。

该属性可使用 1 到 4 个值:

  • 如果规定一个值,比如 div {border-width: thick} - 所有四个边框都是粗线。
  • 如果规定两个值,比如 div {border-width: thick thin} - 上下边框是粗线,而左右边框是细线。
  • 如果规定三个值,比如 div {border-width: thick thin medium}- 上边框是粗线,左右边框是细线,下边框是中等 (medium) 的宽度。
  • 如果规定四个值,比如 div {border-width: thick thin medium 10px} - 上边框是粗线,右边框是细线,下边框是中等的宽度,而左边框是 10px 的宽度。

语法:

  1. Object.style.borderWidth=thin|medium|thick|length

可能的值:

描述
thin 定义细的下边框。
medium 默认。定义中等的下边框。
thick 定义粗的下边框。
length 允许您自定义下边框的宽度。

实例

本例改变边框的宽度:

  1. <html>
  2. <head>
  3. <style type="text/css">
  4. p
  5. {
  6. border: thin solid #FF0000
  7. }
  8. </style>
  9. <script type="text/javascript">
  10. function changeBorderWidth()
  11. {
  12. document.getElementById("p1").style.borderWidth="thick thin";
  13. }
  14. </script>
  15. </head>
  16. <body>
  17.  
  18. <input type="button" onclick="changeBorderWidth()"
  19. value="Change border widths" />
  20.  
  21. <p id="p1">This is a paragraph</p>
  22.  
  23. </body>
  24. </html>