.form-control {
border: 1px solid #ced4da;
border-radius: .375rem; /* 6px 圓角 */
transition: border-color .15s, box-shadow .15s;
}
.form-control:focus {
border-color: #86b7fe;
box-shadow: 0 0 0 .25rem rgba(13,110,253,.25);
outline: none; /* 移除預設藍框 */
}
/* 隱藏原生 */
.custom-check-input { position: absolute; opacity: 0; pointer-events: none; }
/* 自訂框 */
.custom-check-label {
position: relative;
display: inline-flex;
align-items: center;
cursor: pointer;
padding-left: 1.5rem;
}
.custom-check-label::before {
content: "";
position: absolute;
left: 0; top: 50%; transform: translateY(-50%);
width: 1rem; height: 1rem;
border: 2px solid #adb5bd;
border-radius: .25rem;
background: #fff;
transition: background-color .15s, border-color .15s;
}
/* 勾選態 */
.custom-check-input:checked + .custom-check-label::before {
background-color: #0d6efd;
border-color: #0d6efd;
background-image: url("data:image/svg+xml,%3csvg xmlns='https://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='m6 10 3 3 6-6'/%3e%3c/svg%3e");
background-size: 65% 65%;
background-position: center;
background-repeat: no-repeat;
}
/* Focus 可見性 */
.custom-check-input:focus + .custom-check-label::before {
box-shadow: 0 0 0 .25rem rgba(13,110,253,.25);
}
| 場景 | CSS |
|---|---|
| 底線輸入框 | border:0; border-bottom:2px solid #ccc; border-radius:0; |
| 發光邊框 | box-shadow:0 0 0 3px rgba(13,110,253,.4); |
| 錯誤態 | border-color:#dc3545; box-shadow:0 0 0 .25rem rgba(220,53,69,.25); |
| 成功態 | border-color:#198754; box-shadow:0 0 0 .25rem rgba(25,135,84,.25); |
<input type="radio" name="action" value="sub"
style="border:dashed 1px; background:#FEF5C8;">
生產環境請移至外部 CSS 類別,便於維護與主題切換。