提示文字需满足高对比度(≥7:1)、最小字号13px加粗、禁用斜体、行高1.4,并叠加图标等非色彩线索,响应式自适应布局且语义明确。
默认的 color: #666 或 color: #999 在多数背景上对比度不足,尤其对中老年用户或弱光环境。WCAG 最低要求文本与背景对比度 ≥ 4.5:1,但提示类文字建议做到 ≥ 7:1。
#999 配白色背景——实测对比度仅 4.1,不达标#d32f2f(Material Design 红)配白底,对比度 7.3,语义明确且醒目#000,改用 #e53e3e 配 #1a202c 背景,对比度仍达 7.1#ff6b6b(太粉、像强调而非警告)很多初学者直接套用 font-size: 12px + font-weight: normal,结果在 14 英寸笔记本上几乎看不见。提示信息不是辅助说明,是需要被读取的关键信号。
font-size: 13px(iOS Safari 最小可读尺寸下限)font-weight: 500 或 600,别用 400;500 在多数系统里已足够清晰font-style: italic——斜体降
line-height: 1.4,过大会割裂文字与表单控件的视觉关联约 8% 的男性存在红绿色觉缺陷,纯靠 color: #2e7d32(成功绿)和 color: #d32f2f(错误红)无法传递信息。必须叠加非色彩线索。
⚠️ 或 SVG 图标(),确保图标有 aria-hidden="true"
color: #2e7d32,错误用 ❌ + color: #d32f2f,图标本身不依赖颜色传达含义data-status="error" 这类属性配合 CSS,方便后续加 screen reader 支持(如 aria-live="polite")固定宽容器里放长提示,或用 position: absolute 贴着输入框下方,一到小屏就错位甚至消失。提示必须随内容自适应,且优先级高于其他元素。
min-width: fit-content,避免被父容器压缩换行margin-top: 4px 替代 position: absolute,保证文档流内自然跟随max-width: 100% 和 word-break: break-word,防超长邮箱/URL 撑破布局z-index: 1000 以上,并测试是否被 modal、header 遮挡.form-tip {
font-size: 13px;
font-weight: 500;
line-height: 1.4;
margin-top: 4px;
min-width: fit-content;
max-width: 100%;
word-break: break-word;
}
.form-tip.error {
color: #d32f2f;
}
.form-tip.success {
color: #2e7d32;
}
.form-tip::before {
content: "⚠️ ";
display: inline;
}
.form-tip.success::before {
content: "✅ ";
}
真正难的不是选个亮色或调大字号,而是让提示在任何设备、任何视力条件下,都**先于用户意识到问题之前就完成传达**。颜色和字体只是入口,背后得有一整套视觉层级、语义标记和响应逻辑兜底。