как кликнуть значок поиска в поле ввода формы с помощью CSS - PullRequest
0 голосов
/ 25 февраля 2019

Я вставляю значок поиска в поле ввода формы.Как это

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 голосов
/ 25 февраля 2019

* {
    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>
0 голосов
/ 25 февраля 2019

Используйте значок поиска Font Awesome , как показано ниже:

#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>
0 голосов
/ 25 февраля 2019

Вам нужно поле для отправки, чтобы отправить запрос на получение.

 <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

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...