Change the width of the four borders of a <div> element:
document.getElementById("myDiv").style.borderWidth = "thick";
Try it Yourself »
The borderWidth property sets or returns the width of an element's border.
This property can take from one to four values:
Property | |||||
---|---|---|---|---|---|
borderWidth | Yes | Yes | Yes | Yes | Yes |
Return the borderWidth property:
object.style.borderWidth
Set the borderWidth property:
object.style.borderWidth = "thin|medium|thick|
length|initial|inherit"
Value | Description |
---|---|
thin | Defines a thin border |
medium | Defines a medium border. This is default |
thick | Defines a thick border |
length | The width of the border in length units |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
Default Value: | medium |
---|---|
Return Value: | A String, representing the width of an element's border |
CSS Version | CSS1 |
Change the width of the top and bottom border to thick, and the left and right border to thin of a <div> element:
document.getElementById("myDiv").style.borderWidth = "thick thin";
Try it Yourself »
Change the width of the four borders of a <div> element, using the length value:
document.getElementById("myDiv").style.borderWidth = "1px 5px 10px 20px";
Try it Yourself »
Return the width of the border of a <div> element:
alert(document.getElementById("myDiv").style.borderWidth);
Try it Yourself »
CSS tutorial: CSS Border
CSS reference: border-width property
HTML DOM reference: border property
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!