คุณสมบัติ border-style ใน CSS ใช้ระบุรูปแบบขอบขององค์ประกอบ สามารถกำหนดรูปแบบแต่ละด้านแยกได้ด้วย border-top-style, border-right-style, border-bottom-style, border-left-style
ไวยากรณ์ (Syntax)
Selector {
border-style: /*value*/;
}
ตัวอย่างที่ 1: Border-style หลายรูปแบบ
<!DOCTYPE html>
<html>
<head>
<style>
div:first-of-type { margin: 5% 0 0 20%; }
div { height: 40px; width: 40px; margin: auto; padding: 10px; border-style: solid; display: flex; float: left; }
#d1 { border-style: double dashed; }
#d2 { border-style: dotted; }
</style>
</head>
<body>
<div></div> <div id="d1"></div> <div id="d2"></div>
</body>
</html>
ผลลัพธ์

ตัวอย่างที่ 2: Ridge และ Double พร้อม Radius
<!DOCTYPE html>
<html>
<head>
<style>
div { margin: 20px; float: left; height: 80px; width: 60px; border-style: ridge; border-width: 1.2em; border-color: midnightblue; border-bottom-left-radius: 50%; }
div + div { height: 120px; width: 80px; border-style: double; border-color: seagreen; border-right-width: 180px; border-bottom-right-radius: 100%; }
</style>
</head>
<body>
<div></div> <div></div>
</body>
</html>
ผลลัพธ์

ค่าของ border-style
| ค่า | คำอธิบาย | รูปแบบ |
|---|---|---|
none | ไม่มีขอบ (ค่าเริ่มต้น) | - |
hidden | เหมือน none แต่ priority สูงกว่าใน border-collapse | - |
solid | เส้นทึบ | ━━━ |
dashed | เส้นขีด | ━ ━ ━ |
dotted | เส้นจุด | • • • |
double | เส้นคู่ | ═══ |
groove | ข่าวแกะ (3D) | ▽▽▽ |
ridge | ขอบยื่น (3D) | △△△ |
inset | ดูเหมือน陷进去 (3D) | □ |
outset | ดูเหมือนยื่นออก (3D) | □ |
รูปแบบ Shorthand (1-4 ค่า)
border-style: solid; /* ทุกด้าน */
border-style: solid dashed; /* top/bottom, right/left */
border-style: solid dashed dotted; /* top, right/left, bottom */
border-style: solid dashed dotted double; /* top, right, bottom, left */
Logical Properties (Modern)
border-block-style: solid dashed; /* block-start, block-end */
border-inline-style: dotted double; /* inline-start, inline-end */
เคล็ดลับ
border-style: noneหรือhiddenทำให้border-widthกลายเป็น 0- 3D styles (
groove,ridge,inset,outset) ต้องการborder-widthค่อนข้างหนา (≥2px) จึงเห็นชัด doubleต้องการ width ≥ 3px (1px line + 1px gap + 1px line)