html
html
1
2
3
4
5
6
7
8
9
10
11
12
13
<!DOCTYPE html>
<html>
<body>
<div>
<button onclick="openMenu()" class="btn">Click Me!</button>
<div id="dropdown" class="hidden">
<a>Item 1</a>
<a>Item 2</a>
<a>Item 3</a>
</div>
</div>
</body>
</html>
Enter to Rename, Shift+Enter to Preview
css
css
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
body
{
background-color:#2e2e2e;
}
.btn
{
background-color:#c6c6c6;
color:black;
padding:16px;
font-size:16px;
border:none;
cursor:pointer;
width:200px;
outline:none;
border-radius:5px;
}
.btn:hover, .btn:focus
{
background-color:#949494;
}
#dropdown
{
position: absolute;
margin-left:10px;
background-color:#e9e9e9;
width:180px;
box-shadow:0px 8px 16px 0px rgba(0,0,0,0.2);
}
Enter to Rename, Shift+Enter to Preview
js
js
1
2
3
4
5
6
7
8
9
10
11
12
function openMenu()
{
document.getElementById("dropdown").className = "visible";
}
//close the dropdown if the user clicks outside
window.onclick = function(event)
{
if(!event.target.matches('.btn'))
{
document.getElementById("dropdown").className = "hidden";
}
}
Enter to Rename, Shift+Enter to Preview
BROWSER
Console
Run