border-style: dashed 產生虛線邊框。透過單向屬性(border-top/right/bottom/left)可精確控制哪幾邊顯示虛線。
| 需求 | CSS 寫法 | 說明 |
|---|---|---|
| 四邊虛線 | border: 1px dashed #000; | 縮寫,四邊同樣式 |
| 左邊虛線 | border-left: 1px dashed #000; | 單邊 |
| 右邊虛線 | border-right: 1px dashed #000; | 單邊 |
| 上邊虛線 | border-top: 1px dashed #000; | 單邊 |
| 下邊虛線 | border-bottom: 1px dashed #000; | 單邊 |
| 三邊虛線(無右邊) | border: 1px dashed #000; border-right: 0; | 先設四邊,再覆蓋移除右邊,**順序很重要** |
.hackhome { border: 1px dashed #000; height: 50px; width: 350px; }
.hackhome-1 { border-left: 1px dashed #000; height: 50px; width: 350px; }
.hackhome-2 { border-right: 1px dashed #000; height: 50px; width: 350px; }
.hackhome-3 { border-top: 1px dashed #000; height: 50px; width: 350px; }
.hackhome-4 { border-bottom: 1px dashed #000; height: 50px; width: 350px; }
.hackhome-5 { border: 1px dashed #000; border-right: 0; height: 50px; width: 350px; }
HTML 只需對應 class:<div class="hackhome-5">右邊無邊框,其它三邊虛線</div>
標準 CSS 無法直接調整虛線長度/間距。若需精確控制,可用:
background-image: linear-gradient(...) 模擬虛線(可控制 dash/gap 長度)。border-image 使用 SVG 圖片定義虛線樣式。<path stroke-dasharray="5,3"> 最靈活。