If you reduce the screen size, the menu will disappear and you will have the hamburger icon to toggle its visibility. Here is the relevant code:
nav input {
position: fixed;
bottom: 20px;
right: 20px;
width: 40px;
aspect-ratio: 1;
padding: 20px;
display: none;
overflow: hidden;
box-sizing: content-box;
background: teal;
border-radius: 50%;
}
@media (max-width:600px) {
body {
grid-template-columns: 1fr; /* one column setting */
}
nav {
position: fixed; /* make the menu fixed position */
top: 0;
left: 0;
}
nav ul{
transform: translateX(-100%); /* we slide the menu to the left */
transition: .5s;
}
nav input:checked + ul {
transform: translateX(0); /* we show it on checked */
}
nav input {
display: grid; /* input visible only on small screen */
}
}
That’s it! We already have our responsive sidebar menu. We only need a few updates to turn a classic menu into a sidebar menu.
Starting from this code we can do different adjustments to create variations of the same menu and add a few more effects.
We can for example add a semi-transparent overlay above the content when the menu is opened. For this, we can consider a simple box-shadow applied to the <ul> element like the below:
nav ul{
box-shadow: 0 0 0 100vmax #0000; /* a big transparent box-shadow */
}
nav input:checked + ul {
box-shadow: 0 0 0 100vmax #0005; /* we update color on checked to a semi transparent one */
}