<hr> 不只是一條線。善用 CSS 與 IE 濾鏡,能創造漸變透明、紡錘形、虛線、雙線、陰影、發光、甚至垂直分割線等豐富視覺效果。本文匯總 9 種經典特效代碼,可直接復用。
| 屬性 | 說明 |
|---|---|
| color | 線條顏色(舊屬性,建議用 CSS border-color) |
| width | 寬度(像素或百分比) |
| size | 粗細/高度(像素) |
| align | left / center / right 對齊 |
| noshade | 無立體陰影(實心線) |
<hr style="border:0; height:3px; background: linear-gradient(to right, transparent, #987cb9, transparent);" />
<!-- 兼容舊 IE -->
<hr style="filter: alpha(opacity=100, finishopacity=0, style=3); width:80%; color:#987cb9; height:3px;" />
<hr style="border:0; height:10px; border-radius:5px; background:#987cb9;" />
<!-- 兼容舊 IE -->
<hr style="filter: alpha(opacity=100, finishopacity=0, style=2); width:80%; color:#987cb9; height:10px;" />
<hr style="border:0; height:3px; background: linear-gradient(to right, #987cb9, transparent);" />
<!-- 兼容舊 IE -->
<hr style="filter: alpha(opacity=100, finishopacity=0, style=1); width:80%; color:#987cb9; height:3px;" />
<hr style="border:0; height:3px; background: linear-gradient(to right, transparent, #987cb9);" />
<!-- 兼容舊 IE -->
<hr style="filter: alpha(opacity=0, finishopacity=100, style=1); width:80%; color:#987cb9; height:3px;" />
<hr style="border:0; border-top: 1px dashed #987cb9; width:80%;" />
<!-- 舊寫法 -->
<hr style="border:1px dashed #987cb9; width:80%; height:1px;" />
<hr style="border:0; border-top: 3px double #987cb9; width:80%;" />
<hr style="border:0; height:1px; background:#987cb9; box-shadow: 0 2px 4px rgba(152,124,185,0.4);" />
<!-- 兼容舊 IE -->
<hr style="filter: progid:DXImageTransform.Microsoft.Shadow(color:#987cb9, direction:145, strength:15); width:80%; height:1px;" />
<hr style="border:0; height:1px; background:#987cb9; box-shadow: 0 0 8px #987cb9;" />
<!-- 兼容舊 IE -->
<hr style="filter: progid:DXImageTransform.Microsoft.Glow(color=#987cb9, strength=10); width:80%; height:1px;" />
<!-- 現代 CSS 方案 -->
<div style="width:1px; height:265px; background:#987cb9; margin:0 auto;"></div>
<!-- 舊表格方案 -->
<table border="0" cellpadding="0" cellspacing="0" style="height:265px; border-left:1px solid #987cb9;">
<tr><td></td></tr>
</table>
<style>
.divider { border:0; height:1px; margin:1em auto; width:80%; }
.divider-dashed { border-top:1px dashed var(--c); }
.divider-double { border-top:3px double var(--c); }
.divider-fade { background: linear-gradient(to right, transparent, var(--c), transparent); }
.divider-fade-left { background: linear-gradient(to right, transparent, var(--c)); }
.divider-fade-right { background: linear-gradient(to right, var(--c), transparent); }
.divider-spindle { height:10px; border-radius:5px; background:var(--c); }
.divider-vertical { width:1px; height:200px; margin:0 auto; background:var(--c); }
</style>
<hr class="divider divider-fade" style="--c:#987cb9">
<hr class="divider divider-dashed" style="--c:#987cb9">
<div class="divider divider-vertical" style="--c:#987cb9"></div>