Skip to content

Instantly share code, notes, and snippets.

@pixelastic
Created January 9, 2018 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pixelastic/562bc8420afbd98cf95e4b0830d6c931 to your computer and use it in GitHub Desktop.
Save pixelastic/562bc8420afbd98cf95e4b0830d6c931 to your computer and use it in GitHub Desktop.
A Search Engine in CSS
<input type="search" value="Tim" />
<div id="result"></div>
// Show only for matching keywords
input[value="alexandre" i] ~ #results #result15,
input[value="alexandre" i] ~ #results #result16,
input[value="alexandre" i] ~ #results #result17 {
display: block
}
<input type="search" value=""
oninput="this.setAttribute('value', this.value)"
/>
input[value="tim" i] ~ #result:before {
content: "Tim Carry";
}
<!-- one div per employee -->
<div id="results">
<div id="result0"></div>
<div id="result1"></div>
<div id="result2"></div>
[…]
<div id="result148"></div>
<div id="result149"></div>
<div id="result150"></div>
</div>
// Pre-fill the content
#result0:before { content: "Aurora Pleguezelo" }
// […]
#result15:before { content: "Alexandre Collin" }
#result16:before { content: "Alexandre Meunier" }
#result17:before { content: "Alexandre Stanislawski" }
// […]
#result150:before { content: "Zo Asmail" }
// Hide them all
#results div { display: none }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment