如何自定义HTML各类Input输入框的样式?
- 内容介绍
- 文章标签
- 相关推荐
本文共计896个文字,预计阅读时间需要4分钟。
许多人以把 type= 作为开头的内容进行创新。
常见踩坑点:
- 用
type="number"却没隐藏 spinner(上下箭头),导致 PC 端多出两列小按钮 - 用
type="search"后不重置::-webkit-search-cancel-button,× 按钮和设计稿颜色/大小不一致 - 在 iOS 上用
type="date",但没设value="2026-04-30"(ISO 格式),直接显示 “Invalid Date”
统一 box-sizing 和 placeholder 兼容写法
所有文本类输入框(input[type="text"]、input[type="email"]、input[type="search"]、input[type="tel"])必须加 box-sizing: border-box;,否则 padding 和 border 会撑宽元素,响应式布局里极易溢出或换行。
本文共计896个文字,预计阅读时间需要4分钟。
许多人以把 type= 作为开头的内容进行创新。
常见踩坑点:
- 用
type="number"却没隐藏 spinner(上下箭头),导致 PC 端多出两列小按钮 - 用
type="search"后不重置::-webkit-search-cancel-button,× 按钮和设计稿颜色/大小不一致 - 在 iOS 上用
type="date",但没设value="2026-04-30"(ISO 格式),直接显示 “Invalid Date”
统一 box-sizing 和 placeholder 兼容写法
所有文本类输入框(input[type="text"]、input[type="email"]、input[type="search"]、input[type="tel"])必须加 box-sizing: border-box;,否则 padding 和 border 会撑宽元素,响应式布局里极易溢出或换行。

