You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何调整input的placeholder位置?CSS设置无效求助

解决输入框Placeholder左偏移问题

你遇到的margin-left对::placeholder无效的问题,是因为该伪元素在多数浏览器中属于行内元素,水平margin设置通常不生效。可以用以下两种有效方法实现需求:

方法一:给输入框添加内边距

这个方法能让输入文本和placeholder都与左侧保持间距,体验更统一:

#txt-enter {
  padding-left: 10px;
}

方法二:给Placeholder伪元素设置文本缩进

如果只想单独偏移placeholder,输入文本不需要间距的话,可使用此方法:

#txt-enter::placeholder {
  text-indent: 10px;
}

内容的提问来源于stack exchange,提问作者Ari

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 01:02:02