如何使用CSS

时间:2019-02-25 03:44:02

标签: php html css wordpress search

我在表单输入字段上插入一个搜索图标。像这样

enter image description here

#searchform {
  position: relative;
}

#searchform:before {
  content: "\f118";
  font-family: "pharma";
  right: 0px;
  position: absolute;
  top: 50%;
  -webkit-transform: translateY(-50%);
  -ms-transform: translateY(-50%);
  transform: translateY(-50%);
  background: #387DD8;
  padding: 10px;
  color: #fff;
  width: 60px;
}
<form role="search" method="get" id="searchform" class="searchform" action="http://">
  <input type="search" id="s" name="s" value="" placeholder="Enter a product name" title="Press enter to search">
</form>

但是该图标不可单击,我想单击此图标,例如将表单提交到该图标。如何添加呢?

3 个答案:

答案 0 :(得分:0)

您需要一个提交字段来提交获取请求。

 <form role="search" method="get" id="searchform" class="searchform" action="http://">
     <input type="search" id="s" name="s" value="" placeholder="Enter a product name" title="Press enter to search">
     <input type="submit" id"submit">
 </form>

然后您可以在#submit而不是#searchform:before上应用样式

答案 1 :(得分:0)

* {
    box-sizing: border-box;
    font-family: inherit;
}

html {
    font-size: 62.25%;
}

body {
    font-family: sans-serif;
    font-size: 1.6rem;
}

#searchform {
 position: relative;
 width: 500px;
 display: flex;
 justify-content: center;
 align-items: center;
}

#s {
    width: 90%;
    height: 100%;
    padding: .8rem;
    border-top-left-radius: .3rem;
    border-bottom-left-radius: .3rem;
    border: 1px solid dodgerblue;
    border-right-color: transparent; 
}

#submit {
    width: 10%;
    height: 100%;
    padding: .8rem;
    border-top-right-radius: .3rem;
    border-bottom-right-radius: .3rem;
    border: 0px;
    background: dodgerblue;
}
<form role="search" method="get" id="searchform" class="searchform" action="http://">
        <input type="search" id="s" name="s" value="" placeholder="Enter a product name" title="Press enter to search">
        <input type="submit" id="submit" value="">
    </form>

答案 2 :(得分:0)

使用Font Awesome search icon如下:

#searchform {
  position: relative;
}

#submit {
  position: absolute;
  background: #387DD8;
  padding: 10px;
  color: #fff;
  width: 60px;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
<form role="search" method="get" id="searchform" class="searchform" action="http://">
  <input type="search" id="s" name="s" value="" placeholder="Enter a product name" title="Press enter to search" />
  <button type="submit" id="submit">
    <i class="fas fa-search"></i>
  </button>
</form>