html+css 实现搜索框

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Search Member</title>
  <style>
    /* Paste your CSS styles here */
    .search_member_container {
      width: calc(100% - 20px);
      height: 60px;
      position: fixed;
      top: 60px;
      z-index: 9999;

      display: flex;
      align-items: center;
      justify-content: center;
    }

    .search_container_start {
      width: 100%;
      height: 50px;
      background-color: white;
      border: 1px solid #efecec;
      position: relative;
    }

    .search_icon_container {
      width: 60px;
      height: 50px;
      position: absolute;
      left: 0;
      top: 0;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .search_icon {
      width: 20px;
      height: 20px;
    }

    .search_input_container {
      width: calc(100% - 100px);
      height: 50px;
      position: absolute;
      left: 60px;
      top: 0;
    }

    .search_input {
      width: 100%;
      height: 100%;
      border: none;
      outline: none;
      padding: 0;
      margin: 0;
    }

    .search_submit_btn_container {
      width: 100px;
      height: 50px;
      background-color: white;
      position: absolute;
      right: 0;
      top: 0;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .search_btn {
      width: 80%;
      height: 80%;
      background-color: #32cd80;
      border-radius: 10px;
      display: flex;
      align-items: center;
      justify-content: center;
      color: white;
    }
  </style>
</head>
<body>
<!-- Search Member Container -->
<div class="search_member_container">
  <!-- Search Input Container + Search Icon + Search Button -->
  <div class="search_container_start">
    <!-- Search Icon Container -->
    <div class="search_icon_container">
      <img class="search_icon" src="images/search.png" alt="Search Icon">
    </div>

    <!-- Search Input Container -->
    <div class="search_input_container">
      <input class="search_input" placeholder="搜索成员">
    </div>

    <!-- Search Submit Button Container -->
    <div class="search_submit_btn_container">
      <!-- Search Button -->
      <div class="search_btn">搜索</div>
    </div>
  </div>
</div>
</body>
</html>

  • 6
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个基本的搜索框下拉列表的实现步骤: 1. HTML结构:在HTML中创建一个输入框和一个下拉列表的容器,下拉列表的容器初始设置为隐藏状态。 ```html <div class="search-container"> <input type="text" placeholder="请输入搜索关键字"> <div class="search-list-container"> <ul class="search-list"></ul> </div> </div> ``` 2. CSS样式:设置输入框的样式和下拉列表容器的样式,下拉列表容器的初始状态设置为 `display:none` 。 ```css .search-container { position: relative; } input[type="text"] { width: 300px; height: 30px; padding: 5px; border: 1px solid #ccc; border-radius: 5px; } .search-list-container { position: absolute; top: 35px; left: 0; z-index: 99; width: 300px; max-height: 200px; overflow-y: auto; background: #fff; border: 1px solid #ccc; border-radius: 5px; display: none; } ``` 3. JS交互:监听输入框的键盘输入事件,在输入框中输入内容时,向后台发送请求获取匹配的搜索结果,将结果渲染到下拉列表中,并将下拉列表容器设置为显示状态。 ```javascript const input = document.querySelector('input[type="text"]'); const searchListContainer = document.querySelector('.search-list-container'); const searchList = document.querySelector('.search-list'); input.addEventListener('input', function(e) { const keyword = e.target.value; if (keyword.trim()) { // 发送请求获取匹配的搜索结果 const searchResults = getSearchResults(keyword); renderSearchList(searchResults); searchListContainer.style.display = 'block'; } else { searchList.innerHTML = ''; searchListContainer.style.display = 'none'; } }); function getSearchResults(keyword) { // 向后台发送请求获取搜索结果 const results = ['搜索结果1', '搜索结果2', '搜索结果3']; return results; } function renderSearchList(results) { let html = ''; results.forEach(result => { html += `<li>${result}</li>`; }); searchList.innerHTML = html; } ``` 以上就是一个简单的搜索框下拉列表的实现方法,您可以根据自己的需求进行样式和交互的修改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值