Youtube video - Click here
Source code - Dropdown menu using HTML CSS JS :
<!DOCTYPE html>
<html>
<head>
<title>
Drop down
</title>
<style>
body {
background-color: #394a51;
color: white;
}
.container {
width: 400px;
margin: 0px auto;
display: flex;
position: relative;
}
.items {
margin: 10px;
font-size: 18px;
font-weight: 800;
}
#drop {
position: absolute;
margin-left: 80px;
}
.dropdown {
list-style-type: none;
margin: 10px 0px;
background-color: #007cb9;
padding: 10px;
border: 3px solid white;
border-radius: 10px;
text-align: center;
transition: 1s;
display: none;
}
.dropdown:hover {
background-color: #f70776;
}
</style>
</head>
<body>
<div class="container">
<div class="items">Home</div>
<div class="items" id="drop">Course
<li class="dropdown">Physics</li>
<li class="dropdown">Maths</li>
<li class="dropdown">Biology</li>
<li class="dropdown">Chemistry</li>
</div>
</div>
<script>
document.getElementById("drop").addEventListener("mouseover", function() {
for (let i = 0; i < document.getElementsByClassName('dropdown').length; i++) {
document.getElementsByClassName("dropdown")[i].style.display = "block";
}
})
document.getElementById("drop").addEventListener("mouseout", function() {
for (let i = 0; i < document.getElementsByClassName('dropdown').length; i++) {
document.getElementsByClassName("dropdown")[i].style.display = "none";
}
})
</script>
</body>
</html>
Post a Comment