将图标放在表单中的输入元素内

2022-01-30 00:00:00 input icons forms html css

如何在表单的输入元素中放置图标?

How do I put an icon inside a form's input element?

现场版:潮汐力主题

推荐答案

您链接的网站使用了 CSS 技巧的组合来实现这一目标.首先,它为 <input> 元素使用背景图像.然后,为了将光标推到上面,它使用 padding-left.

The site you linked uses a combination of CSS tricks to pull this off. First, it uses a background-image for the <input> element. Then, in order to push the cursor over, it uses padding-left.

换句话说,它们有以下两条 CSS 规则:

In other words, they have these two CSS rules:

background: url(images/comment-author.gif) no-repeat scroll 7px 7px;
padding-left:30px;

相关文章