Skip to content

Instantly share code, notes, and snippets.

@wolz-CODElife
Last active May 13, 2021 23:17
Show Gist options
  • Save wolz-CODElife/9807ba4177d926fb5829b4eceebfe9af to your computer and use it in GitHub Desktop.
Save wolz-CODElife/9807ba4177d926fb5829b4eceebfe9af to your computer and use it in GitHub Desktop.
Create Dropdown using HTML, CSS and JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dropdown</title>
</head>
<body>
<style>
/*.hide to compress the height of drop-content*/
.hide{height: 0px}
</style>
<div style="width: 200px">
<button onclick="toggleDrop()" style="width: 100%; padding: 10px;">Dropdown</button>
<div class="drop_content hide" style="overflow: auto;">
<ul style="list-style: none; padding: 5px; border: 1px solid;">
<li><a href="#">Link 1</a></li>
<li><a href="#">Link 2</a></li>
</ul>
</div>
</div>
<script>
function toggleDrop() {
//toggle height(0px OR auto)
document.querySelector('.drop_content').classList.toggle('hide');
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment