【发布时间】:2018-06-10 19:57:31
【问题描述】:
需要回答的问题:
如何在搜索框/表单中添加图标
如何在输入字段中添加图标
我遇到了以下问题,我无法将 FontAwesome fa-search 图标放在输入字段/搜索框的右侧。
这是表单的图片:
A HTML search form on a website's header
此处的表格链接(不是常青树):
https://www.themirrorman.co
这是我的原始代码:
@media screen and (min-width: 800px) {
#header-search-desktop-div {
position: absolute;
left: 180px;
width: 450px;
margin-top: 0;
margin-bottom: 0;
border: 1px solid #881d98;
border-radius: 24px;
}
#header-search-desktop-div #header-search-fa {
position: absolute;
color: #7E7E7E;
z-index: 100;
font-size: 27px;
}
#header-search-desktop-div .fa-search {
top: 5%;
left: 1.5%;
line-height: 0.8em;
}
}
<div id="header-search-desktop-div">
<form role="search" method="get" class="searchform" action="https://themirrorman.co/">
<span id="header-search-fa" class="fa fa-search">
<input id="header-search-desktop-input" name="product-search" type="text" value="" placeholder="Product Search…">
<input type="hidden" name="post_type" value="product" />
</span>
</form>
</div>
我收到了答案并更改了以下代码,它现在可以像上面的图片链接一样工作:
#header-search-submit {
position: absolute;
z-index: 1;
padding: 0;
right: 15px;
top: 6px;
font-size: 24px;
font-family: FontAwesome;
color: #7B7B7B;
cursor: pointer;
background: 0;
border: 0;
}
<div id="header-search-desktop-div">
<form id="header-search-form" role="search" action="https://themirrorman.co/" method="get">
<fieldset>
<span class="text">
<input id="header-search-desktop-span" style="border-radius: 24px;" type="text" value="" name="s" class="s" placeholder="I am looking for..." />
<input id="header-search-submit" type="submit" value="" name="post_type" />
</span>
</fieldset>
</form>
</div>
【问题讨论】:
-
一旦您得到问题的答案,您链接的网站就会发生变化,让未来读者寻找答案的问题无关紧要。通过在问题本身中添加 minimal reproducible example 来确保您的问题仍然相关。
-
您好 Andrei,感谢您的反馈。我现在已经按照你的要求做了,请确认我做的好不好?
-
将答案标记为已接受足以告诉所有人您的问题已解决,您无需将其放入问题中。一般来说,去掉特殊的部分,只留下理解和回答问题所必需的部分,这是将重要问题与其他问题区分开来的事情之一。因为未来的读者会花更少的时间来理解它。感谢您调整您的问题,欢迎来到Stack Overflow。