Skip to content

Instantly share code, notes, and snippets.

@Ashkanph
Created August 18, 2020 12:14
Show Gist options
  • Save Ashkanph/5ed2eea0f811db59713bad3763e51484 to your computer and use it in GitHub Desktop.
Save Ashkanph/5ed2eea0f811db59713bad3763e51484 to your computer and use it in GitHub Desktop.
Select first 3 elements with css
<!DOCTYPE html>
<html>
<head>
<style>
ul > :nth-child(-n+3) {
background:yellow;
}
</style>
</head>
<body>
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment