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