ใช้ Property borderImageWidth เพื่อตั้งค่าความกว้างของ Border Image (รูปภาพเป็นขอบ) แทน Border ธรรมดา
ตัวอย่างโค้ด
<!DOCTYPE html>
<html>
<head>
<style>
div {
background-color: gray;
border: 40px solid;
border-image: url('https://www.tutorialspoint.com/images/neo4j.png');
border-image-slice: 50;
border-image-width: 20px;
border-image-outset: 0;
border-image-repeat: round;
}
</style>
</head>
<body>
<div id="box">
<p>Demo Text!</p>
</div>
<button onclick="display()">Set Width</button>
<script>
function display() {
document.getElementById("box").style.borderImageWidth = "20px 30px";
}
</script>
</body>
</html>
คำอธิบาย borderImageWidth
- ควบคุม ความหนาของ Border Image (แยกจาก border-width)
- รับค่า 1-4 ค่า (Top, Right, Bottom, Left) เช่น CSS Margin/Padding
- หน่วย:
px,em,rem,%, หรือ Number (Multiple ของ border-width) - ตัวอย่าง:
"20px 30px"→ Top/Bottom 20px, Left/Right 30px
Border Image Properties ทั้งหมด
| Property | ความหมาย |
|---|---|
border-image-source | รูปภาพที่ใช้ (url() หรือ gradient) |
border-image-slice | ตัดรูป 9 ส่วน (Corners, Edges, Center) |
border-image-width | ความหนาของ Border Image |
border-image-outset | ขยาย Border Image นอก Box |
border-image-repeat | Repeat Mode: stretch, repeat, round, space |
Shorthand: border-image: source slice / width / outset repeat;