HTML DOM中的Style borderTopWidth属性用于设置或返回元素顶部边框的宽度。
用法:
- 获取borderTopWidth属性
object.style.borderTopWidth
- 设置borderTopWidth属性
object.style.borderTopWidth = "thin | medium | thick | length | initial | inherit"
属性值:
- thin:这用于定义细边框。
例:
<!DOCTYPE html> <html lang="en"> <head> <title> DOM Style BorderTopWidth </title> <style> .elem { border-style:solid; padding:10px; } </style> </head> <body> <h1 style="color:green"> GeeksforGeeks </h1> <b> DOM Style BorderTopWidth </b> <p class="elem"> GeeksforGeeks is a computer science portal with a huge variety of well written and explained computer science and programming articles, quizzes and interview questions. </p> <button onclick="changeWidth()"> Change borderTopWidth </button> <!-- Script to change borderTopWidth --> <script> function changeWidth() { elem = document.querySelector('.elem'); elem.style.borderTopWidth = 'thin'; } </script> </body> </html>
输出:
在单击按钮之前:
单击按钮后:
- medium:这用于定义中等顶部边框。这是默认值。
例:
<!DOCTYPE html> <html lang="en"> <head> <title> DOM Style BorderTopWidth </title> <style> .elem { border:thick solid; padding:10px; } </style> </head> <body> <h1 style="color:green"> GeeksforGeeks </h1> <b> DOM Style BorderTopWidth </b> <p class="elem"> GeeksforGeeks is a computer science portal with a huge variety of well written and explained computer science and programming articles, quizzes and interview questions. </p> <button onclick="changeWidth()"> Change borderTopWidth </button> <!-- Script to change borderTopWidth --> <script> function changeWidth() { elem = document.querySelector('.elem'); elem.style.borderTopWidth = 'medium'; } </script> </body> </html>
输出:
在单击按钮之前:
单击按钮后:
- thick:这用于定义粗大的顶部边框。
示例3:
<!DOCTYPE html> <html lang="en"> <head> <title> DOM Style BorderTopWidth </title> <style> .elem { border-style:solid; padding:10px; } </style> </head> <body> <h1 style="color:green"> GeeksforGeeks </h1> <b> DOM Style BorderTopWidth </b> <p class="elem"> GeeksforGeeks is a computer science portal with a huge variety of well written and explained computer science and programming articles, quizzes and interview questions. </p> <button onclick="changeWidth()"> Change borderTopWidth </button> <!-- Script to change borderTopWidth --> <script> function changeWidth() { elem = document.querySelector('.elem'); elem.style.borderTopWidth = 'thick'; } </script> </body> </html>
输出:
在单击按钮之前:
单击按钮后:
- length:这用于以长度单位定义顶部边框宽度。
示例4:
<!DOCTYPE html> <html lang="en"> <head> <title> DOM Style BorderTopWidth </title> <style> .elem { border-style:solid; padding:10px; } </style> </head> <body> <h1 style="color:green"> GeeksforGeeks </h1> <b> DOM Style BorderTopWidth </b> <p class="elem"> GeeksforGeeks is a computer science portal with a huge variety of well written and explained computer science and programming articles, quizzes and interview questions. </p> <button onclick="changeWidth()"> Change borderTopWidth </button> <!-- Script to change borderTopWidth --> <script> function changeWidth() { elem = document.querySelector('.elem'); elem.style.borderTopWidth = '10px'; } </script> </body> </html>
输出:
在单击按钮之前:
单击按钮后:
- initial:这用于将此属性设置为其默认值。
示例5:
<!DOCTYPE html> <html lang="en"> <head> <title> DOM Style BorderTopWidth </title> <style> .elem { border-style:solid; padding:10px; border-top-width:2px; } </style> </head> <body> <h1 style="color:green"> GeeksforGeeks </h1> <b> DOM Style BorderTopWidth </b> <p class="elem"> GeeksforGeeks is a computer science portal with a huge variety of well written and explained computer science and programming articles, quizzes and interview questions. </p> <button onclick="changeWidth()"> Change borderTopWidth </button> <!-- Script to change borderTopWidth --> <script> function changeWidth() { elem = document.querySelector('.elem'); elem.style.borderTopWidth = 'initial'; } </script> </body> </html>
输出:
在单击按钮之前:
单击按钮后:
- inherit:这将从其父项继承该属性。
示例6:
<!DOCTYPE html> <html lang="en"> <head> <title> DOM Style BorderTopWidth </title> <style> #parent { padding:10px; border-style:solid; /* Setting the borderTopWidth of the parent */ border-top-width:15px; } .elem { border-style:solid; padding:10px; } </style> </head> <body> <h1 style="color:green"> GeeksforGeeks </h1> <b> DOM Style BorderTopWidth </b> <br> <br> <div id="parent"> <p class="elem"> GeeksforGeeks is a computer science portal with a huge variety of well written and explained computer science and programming articles, quizzes and interview questions. </p> </div> <br> <button onclick="changeWidth()"> Change borderTopWidth </button> <!-- Script to change borderTopWidth --> <script> function changeWidth() { elem = document.querySelector('.elem'); elem.style.borderTopWidth = 'inherit'; } </script> </body> </html>
输出:
在单击按钮之前:
单击按钮后:
支持的浏览器:borderTopWidth属性支持的浏览器如下:
- 谷歌浏览器
- IE浏览器
- Firefox
- Opera
- 苹果Safari
相关用法
- HTML Style right用法及代码示例
- HTML Style top用法及代码示例
- HTML Style wordSpacing用法及代码示例
- HTML Style borderRight用法及代码示例
- HTML Style borderLeft用法及代码示例
- HTML Style textAlign用法及代码示例
- HTML Style height用法及代码示例
- HTML Style whiteSpace用法及代码示例
- HTML Style textDecorationLine用法及代码示例
- HTML Style columnRuleStyle用法及代码示例
- HTML Style display用法及代码示例
- HTML Style transformStyle用法及代码示例
- HTML Style visibility用法及代码示例
- HTML Style animationDirection用法及代码示例
- HTML Style columnFill用法及代码示例
注:本文由纯净天空筛选整理自sayantanm19大神的英文原创作品 HTML | DOM Style borderTopWidth Property。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。