border: <width> <style> <color>;
/* 標準順序:寬度 → 樣式 → 顏色 */
border: 1px solid #000;
border: 2px dashed rgb(255,0,0);
border: thick double hsl(200, 50%, 30%);
.box {
border: 1px solid #000; /* 基礎樣式 */
border-width: 1px 2px 3px 4px; /* 上右下左:1px 2px 3px 4px */
}
.box {
border: 1px solid #000; /* 四邊默認 */
border-bottom-width: 3px; /* 只加粗底邊 */
border-left-color: #1890ff; /* 左邊品牌色 */
}
/* 更優雅:邏輯屬性(書寫模式友好) */
.box {
border: 1px solid #000;
border-block-end-width: 3px; /* 底邊 */
border-inline-start-color: #1890ff; /* 左邊(LTR) / 右邊(RTL) */
}
.box {
border: 1px solid #000; /* 全邊開啟 */
border-width: 0 1px 1px 0; /* 關閉上、左;保留右、下 */
}
/* 等效於 */
.box {
border-top: none;
border-right: 1px solid #000;
border-bottom: 1px solid #000;
border-left: none;
}
/* 適配 RTL/LTR/垂直書寫模式 */
border-block: 1px solid; /* 上下邊 */
border-inline: 2px dashed; /* 左右邊 */
border-block-start: 3px solid red; /* 邏輯「開始」邊 */
border-inline-end: 1px dotted blue; /* 邏輯「結束」邊 */
.frame {
border: 10px solid transparent;
border-image: url(border.png) 30 stretch; /* slice width / outset / repeat */
}
.multi-border {
border: 2px solid #000;
box-shadow:
0 0 0 4px #fff, /* 第二層邊框 */
0 0 0 6px #1890ff; /* 第三層邊框 */
/* 或使用 outline + outline-offset */
outline: 2px solid #f00;
outline-offset: 4px;
}
border: 1px #000 ❌ → border: 1px solid #000 ✅(缺省none不顯示)border: 1px solid #000 中#000為#000000簡寫,確保顏色值合法。table { border-collapse: collapse; } 時,border-width四值語法可能表現異常,建議改用單邊屬性。border-radius 不影響border-width計算,但box-shadow跟隨圓角,outline不跟隨。總結:日常開發首選「基礎border + 單邊屬性覆蓋」,語義明確、易於覆蓋與主題切換;複雜裝飾邊框改用box-shadow、outline、border-image或::before/::after偽元素實現,保持結構樣式分離。