如何在搜索字段的输入中包含元素

时间:2015-01-08 16:49:13

标签: html

如何在搜索输入字段中包含 img 等元素或其他元素。我希望结果如下:Image from Google Images Search

我已经尝试过并考虑过这个但是通常你不能将其他代码放在输入标签中。有些人将搜索图标放在其他搜索按钮等等。我怎么能这样做?

1 个答案:

答案 0 :(得分:3)

如果您使用浏览器的开发人员工具来检查示例,例如Google search bar,您会看到他们只是使用绝对定位在相对定位的包装器中对元素进行分层。

.wrapper {position: relative;}
.icon {position: absolute; right: 0; top: 0;}

<div class="wrapper">
    <input ... />
    <div class="icon"></div>
</div>

Demo