| 瀏覽器 | 高度 | 寬度 | 備註 |
|---|---|---|---|
| Firefox | 22px (含邊框) | 146px (含邊框) | |
| Safari | 22px | 146px | |
| Chrome/Edge | 約 20-22px | 約 146px | 視作業系統主題 |
| IE11 | 24px | 146px | 較高 |
type="submit" 同樣存在高度差異 (Firefox 23px、Safari 21px、IE 25px)。
input, textarea, select, button {
/* 字體繼承:input 不會自動繼承父元素字體 */
font-family: inherit;
font-size: inherit;
font-weight: inherit;
line-height: inherit;
color: inherit;
/* 盒模型統一 */
box-sizing: border-box;
/* 移除預設外觀 (需配合具體類型) */
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
/* 移除預設邊框與背景 */
border: none;
background: none;
/* 移除 iOS 陰影/圓角 */
border-radius: 0;
/* 移除 Firefox 內部 padding */
padding: 0;
margin: 0;
}
/* 針對性重置 */
input[type="search"] {
-webkit-appearance: none; /* 移除 Safari 搜尋框預設圓角/放大鏡 */
}
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}
input[type="date"]::-webkit-calendar-picker-indicator {
opacity: 0; /* 隱藏預設日曆圖示,可自訂 */
}
❌ 錯誤:設定 `height` + `line-height` — IE 無法垂直置中
✅ 正確:使用 `padding` 撐開高度,文字自然置中
.input-text {
/* 推薦:padding 控制高度 */
padding: 8px 12px; /* 上下 8px,左右 12px */
font-size: 1rem;
line-height: 1.5; /* 確保行高足夠 */
min-height: 40px; /* 觸控友善最小高度 */
border: 1px solid #ccc;
border-radius: 4px;
background: white;
width: 100%;
box-sizing: border-box;
}
/* 等效高度計算:font-size * line-height + padding-top + padding-bottom
1rem * 1.5 + 8px + 8px ≈ 24px + 16px = 40px */
:root {
--input-height: 40px;
--input-padding-y: 8px;
--input-padding-x: 12px;
--input-font-size: 1rem;
--input-border-color: #d1d5db;
--input-border-radius: 6px;
--input-focus-ring: 0 0 0 3px rgba(59, 130, 246, 0.4);
--input-bg: #fff;
--input-color: #111827;
--input-placeholder-color: #9ca3af;
}
.form-input {
width: 100%;
height: var(--input-height);
padding: var(--input-padding-y) var(--input-padding-x);
font-size: var(--input-font-size);
font-family: inherit;
line-height: 1.5;
color: var(--input-color);
background-color: var(--input-bg);
border: 1px solid var(--input-border-color);
border-radius: var(--input-border-radius);
box-sizing: border-box;
transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.form-input::placeholder { color: var(--input-placeholder-color); }
.form-input:hover { border-color: #9ca3af; }
.form-input:focus {
outline: none;
border-color: #3b82f6;
box-shadow: var(--input-focus-ring);
}
.form-input:disabled {
background-color: #f3f4f6;
color: #6b7280;
cursor: not-allowed;
}
.form-input[aria-invalid="true"] {
border-color: #ef4444;
}
.form-input[aria-invalid="true"]:focus {
box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.4);
}
.form-check {
position: relative;
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
}
.form-check input {
position: absolute;
opacity: 0;
width: 0;
height: 0;
}
.form-check .checkmark {
width: 20px;
height: 20px;
border: 2px solid var(--input-border-color);
border-radius: 4px; /* radio 用 50% */
background: var(--input-bg);
transition: all 0.15s;
}
.form-check input:checked + .checkmark {
background: #3b82f6;
border-color: #3b82f6;
}
.form-check input:checked + .checkmark::after {
content: '';
position: absolute;
left: 6px; top: 2px;
width: 5px; height: 10px;
border: solid white;
border-width: 0 2px 2px 0;
transform: rotate(45deg);
}
.form-check input:focus-visible + .checkmark {
box-shadow: var(--input-focus-ring);
}
.form-select {
/* 基礎樣式同 .form-input */
padding-right: 40px; /* 為自訂箭頭留空間 */
background-image: url("data:image/svg+xml,%3Csvg xmlns='https://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
background-repeat: no-repeat;
background-position: right 12px center;
background-size: 16px;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
.file-upload {
position: relative;
}
.file-upload input[type="file"] {
position: absolute;
inset: 0;
opacity: 0;
cursor: pointer;
width: 100%;
height: 100%;
}
.file-upload .btn { /* 自訂按鈕樣式 */ }