YL

FORM & INPUT

搜索下拉高亮Search with Highlighted Results

搜索框下方实时给出结果,命中的关键词在结果里高亮加粗。

中英对照

中文
搜索下拉高亮
英文
Search with Highlighted Results
别名
搜索结果列表、实时搜索、Search Suggestions
一句话
搜索框下方实时给出结果,命中的关键词在结果里高亮加粗。

效果预览

工作流引擎
▤如何配置工作流引擎?
▥工作流引擎 API 参考
▦工作流引擎常见问题

适合用在哪

全站搜索、帮助中心、文档检索、商品搜索。

不适合:没有类型区分、结果又极少时:不必上复杂下拉,直接跳结果页;也不能把整站导航塞进搜索建议里抢戏。

和相近模式的区别

自动补全输入Combobox / Autocomplete

Combobox 从封闭集合选一项回填;搜索下拉面向开放检索,强调 <mark>/<em> 高亮、类型标签与「查看全部 N 条」。

命令面板Command Palette

命令面板是全局快捷操作;搜索下拉挂在搜索框下,任务是找内容而不是执行命令。

容易踩的坑

  • 直接用 innerHTML 拼接高亮关键词,用户输入特殊字符时可能引发 XSS。
  • 高亮加了黄色背景,结果列表满屏荧光笔,反而找不到真正想要的那条。
  • 防抖低于 100ms 或不取消过期请求,慢网下结果列表频繁跳动闪烁。

设计提示词 · Prompt

搜索下拉高亮(Search with Highlighted Results):搜索框有输入时下方浮出结果面板。每条结果:左侧 24px 类型图标 → 标题(命中的关键词片段用品牌色 650 字重高亮,用 <mark> 或 <em> 包裹)→ 右侧灰色类型标签("文档"/"文章"/"产品")。键盘导航当前项浅灰底。面板底部固定一行"查看全部 N 条结果 →"。高亮要克制:只变颜色字重,不加背景色,否则满屏荧光笔。防抖 150-250ms 再发请求,请求图标显示在输入框右侧。
Search with Highlighted Results: when the search box has input, a results panel floats below it. Each result: a 24px type icon on the left → title (matched keyword fragments highlighted in brand color at 650 weight, wrapped in <mark> or <em>) → a gray type tag on the right ("Docs" / "Article" / "Product"). The keyboard-navigated current item has a light gray background. A fixed row at the bottom of the panel: "View all N results →". Keep highlighting restrained: change only color and weight, no background color, otherwise the screen is full of highlighter marks. Debounce 150-250ms before sending requests, with a loading icon shown on the right side of the input.

可复制 CSS

自包含的最小实现,粘贴到空白页面即可生效;类名可以按项目规范改名。

/* 搜索框 + 高亮结果 + 底部查看全部 */
.searchdd { position: relative; width: min(420px, 100%); }
.searchdd__box {
  display: flex;
  align-items: center;
  height: 44px;
  padding: 0 12px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  background: #fff;
  font: 15px/1 system-ui, sans-serif;
}
.searchdd__box:focus-within {
  border-color: #4f46e5;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .12);
}
.searchdd__res {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 20;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 16px 40px -12px rgba(0, 0, 0, .18);
  overflow: hidden;
}
.searchdd__r {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 12px;
  font: 14px/1.35 system-ui, sans-serif;
  color: #111827;
  cursor: pointer;
}
.searchdd__r.is-on,
.searchdd__r:hover { background: #f3f4f6; }
.searchdd__r em,
.searchdd__r mark {
  font-style: normal;
  font-weight: 650;
  color: #4f46e5;
  background: transparent;
}
.searchdd__more {
  display: block;
  padding: 12px;
  border-top: 1px solid #e5e7eb;
  font: 600 13px/1 system-ui, sans-serif;
  color: #4f46e5;
  text-decoration: none;
}

演示 HTML 结构

<div class="s d-searchdd">
  <div class="d-searchdd__box">工作流<b>引擎</b></div>
  <div class="d-searchdd__res">
    <div class="d-searchdd__r"><span class="d-ico" style="width:17px;height:17px;font-size:9px">▤</span><span>如何配置工作流<em>引擎</em>?</span></div>
    <div class="d-searchdd__r is-on"><span class="d-ico" style="width:17px;height:17px;font-size:9px">▥</span><span>工作流<em>引擎</em> API 参考</span></div>
    <div class="d-searchdd__r"><span class="d-ico" style="width:17px;height:17px;font-size:9px">▦</span><span>工作流<em>引擎</em>常见问题</span></div>
  </div>
</div>

常见问题

搜索下拉高亮的英文是什么?

搜索下拉高亮的英文是 Search with Highlighted Results。常见英文别名还包括 Search Suggestions。

Search with Highlighted Results 的中文是什么?

Search with Highlighted Results 的中文是「搜索下拉高亮」。常见中文别名还包括 搜索结果列表、实时搜索。搜索框下方实时给出结果,命中的关键词在结果里高亮加粗。

高亮为什么不加背景色?

只改颜色与字重(650),避免满屏「荧光笔」。背景高亮适合正文检索页,不适合密集下拉。

请求要防抖多久?

150–250ms。输入框右侧可放小号请求指示;清空输入时立刻收起面板。

常见搭配

同一页面里经常和「搜索下拉高亮」一起出现的模式,可以收藏后用「组合收藏为整页提示词」一起交给 AI。

标签