Last active
May 13, 2021 23:17
-
-
Save wolz-CODElife/9807ba4177d926fb5829b4eceebfe9af to your computer and use it in GitHub Desktop.
Create Dropdown using HTML, CSS and JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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