HTML 样式变成了简单的搜索功能

HTML style into simple search funtion

我正在创建一个简单的 html 页面作为 firefox 默认主页。我可以使用搜索功能,但现在我想在页面中添加样式。

这是我的功能:

    <form action="" onsubmit="return false">
  <input name="term_1" size="38" maxlength="50" value="" id="searchbox" placeholder="Enter search term.."><br />
  <select name="field_1" id="option">
    <option value="t" selected="selected">Title</option>
    <option value="a">Author</option>
    <option value="s">Subject</option>
    <option value="call_number">Call Number</option>
    <option value="p">Publisher</option>
  </select>

  <input value="Submit"  type="button" onclick=search()>
  <input value="Reset" type="reset">
</form>

<script>
function search()
{
   var search_input=document.getElementById("searchbox").value;// value of search box
   var option=document.getElementById("option").value; //value of select

   window.open('http://webpac.kdu.edu.my/search/query?match_1=MUST&field_1=' + option + '&term_1=' + search_input + '&facet_loc=20000&sort=relevance&theme=kdu', 'bswindow');   //proceed with search
}
</script>

我想要这样的风格

https://www.w3schools.com/code/tryit.asp?filename=GAQ6A12ICCQF

查看 W3schools css 页面了解更多样式 https://www.w3schools.com/howto/howto_css_searchbar.asp

要设置样式,您必须应用 CSS。

根据 WW3 Schools Search Button Styling

我通过以下方式修改了您的 HTML 代码以实现此目的:

  • 将您的 Submit 输入更改为键入 button 以允许内部文本项(用于放大镜搜索符号)。
  • 出于与上述相同的原因,已将您的 Reset 输入转换为类型 button
  • input[type="term1"] 移到 select 之后,以便与您提供的样式简介保持一致。
  • head 中包含对 FontAwesome 库的引用,因此可以使用刷新和放大镜符号
  • 在相关 <button
  • 内的 <i> 标签中引用了刷新和放大镜符号

这是更新后的 HTML CSS:

* {
  font-size: 14px;
}

select {
  height: 35px;
  border: 1px solid grey;
  background: #f1f1f1;
}

input[type="text"] {
  height: 30px;
  text-indent: 10px;
  border: 1px solid grey;
  background: #f1f1f1;
}

form {
  display: flex;
  flex-direction: row;
  width: 100%;
}

input[name="term_1"] {
  width: 100%;
}

button {
  width: 100px;
  background-color: #2196F3;
  border: 1px solid grey;
  color: white;
}

button:hover {
  cursor: pointer;
  background-color: #0b7dda;
}
<head>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

</head>

<form action="" onsubmit="return false">
  <select name="field_1" id="option">
    <option value="t" selected="selected">Title</option>
    <option value="a">Author</option>
    <option value="s">Subject</option>
    <option value="call_number">Call Number</option>
    <option value="p">Publisher</option>
  </select>
  <input type="text" name="term_1" size="38" maxlength="50" value="" id="searchbox" placeholder="Enter search term.."><br />
  <button type="submit" onclick=search()><i class="fa fa-search" aria-hidden="true"></i></button>
  <button type="reset"><i class="fa fa-refresh" aria-hidden="true"></i>
  </button>
</form>

<script>
  function search() {
    var search_input = document.getElementById("searchbox").value; // value of search box
    var option = document.getElementById("option").value; //value of select

    window.open('http://webpac.kdu.edu.my/search/query?match_1=MUST&field_1=' + option + '&term_1=' + search_input + '&facet_loc=20000&sort=relevance&theme=kdu', 'bswindow'); //proceed with search
  }

</script>

这里也有一个JSFiddle供参考

<div id="cover">
  <form method="get" action="">
    <div class="tb">
      <div class="td"><input type="text" placeholder="Search" required></div>
      <div class="td" id="s-cover">
        <button type="submit">
          <div id="s-circle"></div>
          <span></span>
        </button>
      </div>
    </div>
  </form>
</div>


*
{
    outline: none;
}
html, body
{
    height: 100%;
    min-height: 100%;
}
body
{
    margin: 0;
    background-color: #ffd8d8;
}
.tb
{
    display: table;
    width: 100%;
}
.td
{
    display: table-cell;
    vertical-align: middle;
}
input, button
{
    color: #fff;
    font-family: Nunito;
    padding: 0;
    margin: 0;
    border: 0;
    background-color: transparent;
}
#cover
{
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    width: 550px;
    padding: 35px;
    margin: -83px auto 0 auto;
    background-color: #ff7575;
    border-radius: 20px;
    box-shadow: 0 10px 40px #ff7c7c, 0 0 0 20px #ffffffeb;
    transform: scale(0.6);
}
form
{
    height: 96px;
}
input[type="text"]
{
    width: 100%;
    height: 96px;
    font-size: 60px;
    line-height: 1;
}
input[type="text"]::placeholder
{
    color: #e16868;
}
#s-cover
{
    width: 1px;
    padding-left: 35px;
}
button
{
    position: relative;
    display: block;
    width: 84px;
    height: 96px;
    cursor: pointer;
}
#s-circle
{
    position: relative;
    top: -8px;
    left: 0;
    width: 43px;
    height: 43px;
    margin-top: 0;
    border-width: 15px;
    border: 15px solid #fff;
    background-color: transparent;
    border-radius: 50%;
    transition: 0.5s ease all;
}
button span
{
    position: absolute;
    top: 68px;
    left: 43px;
    display: block;
    width: 45px;
    height: 15px;
    background-color: transparent;
    border-radius: 10px;
    transform: rotateZ(52deg);
    transition: 0.5s ease all;
}
button span:before, button span:after
{
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 45px;
    height: 15px;
    background-color: #fff;
    border-radius: 10px;
    transform: rotateZ(0);
    transition: 0.5s ease all;
}
#s-cover:hover #s-circle
{
    top: -1px;
    width: 67px;
    height: 15px;
    border-width: 0;
    background-color: #fff;
    border-radius: 20px;
}
#s-cover:hover span
{
    top: 50%;
    left: 56px;
    width: 25px;
    margin-top: -9px;
    transform: rotateZ(0);
}
#s-cover:hover button span:before
{
    bottom: 11px;
    transform: rotateZ(52deg);
}
#s-cover:hover button span:after
{
    bottom: -11px;
    transform: rotateZ(-52deg);
}
#s-cover:hover button span:before, #s-cover:hover button span:after
{
    right: -6px;
    width: 40px;
    background-color: #fff;
}

搜索栏演示。你可以关注这个。

如果你想要更多不同的。你可以检查这个:https://freefrontend.com/css-search-boxes/