responsive 1-Level Menu by Myri (@mynimi ) on CodePen .
I use Font-Awesome and jQuery here because I always have those in my projectrs. But you can create a menu like that, with CSS only. If you are interested in a tutorial, let me know.
Since I use my menus in the header area that’s what I did here as well, because I did not want my toggle link floating arount in the emptyness. There are two. One within the nav
element, that I use to wrap the items and one within. They will toggle the off-canvas. So only used for that version.
And so that markup is written a little faster, I will use jade
a .toggle-link ( href = ' #menu ' )
| < i class = " fa fa-navicon " ></ i > Menu
a .toggle-link ( href = ' #menu ' )
each val in [ 1 , 2 , 3 , 4 , 5 ]
a ( href = ' index ' + val + ' .html ' )= ' Item ' + val
This will result in the following HTML
< a href = " #menu " class = " toggle-link " >
< i class = " fa fa-navicon " ></ i > Menu
< nav id = " menu " class = " main-menu " >
< a href = " #menu " class = " toggle-link " >
< i class = " fa fa-close " ></ i >
< a href = " index1.html " >Item 1</ a >
< a href = " index2.html " >Item 2</ a >
< a href = " index3.html " >Item 3</ a >
< a href = " index4.html " >Item 4</ a >
< a href = " index5.html " >Item 5</ a >
Styling is done with Flexbox. And Sass, because I will never write plain CSS again. Comments will explain a bit further.
// point at which menu turns to off-canvas
background : darken ( white , 15 % );
color : lighten ( black , 50 % );
// change the way links appear with flex-direction
// on a horizontal line in non-collapsed way
@media screen and ( min-width : $menu_collapse ) {
justify-content : space-between ;
@media screen and ( max-width : $menu_collapse ) {
// make links appear underneath each other
justify-content : flex-start ;
// off-canvas style, closed
background : darken ( white , 10 % );
transition : .3 s all linear ;
transform : translateX ( -320 px );
transform : translateX ( 0 px );
// position "x" in the upper right-hand corner
// make toggle links visible if off-canvas menu is to be displayed
@media screen and ( min-width : $menu_collapse ) {
and that’s what the styles look like after sass and autoprefixer did their work
-webkit-box-align : center ;
-webkit-align-items : center ;
@media screen and ( min-width : 500 px ) {
-webkit-box-orient : horizontal ;
-webkit-box-direction : normal ;
-webkit-flex-direction : row ;
-webkit-box-pack : justify ;
-webkit-justify-content : space-between ;
justify-content : space-between ;
.main-menu .toggle-link {
@media screen and ( max-width : 500 px ) {
-webkit-box-orient : vertical ;
-webkit-box-direction : normal ;
-webkit-flex-direction : column ;
-ms-flex-direction : column ;
-webkit-justify-content : flex-start ;
justify-content : flex-start ;
-webkit-transition : .3 s all linear ;
transition : .3 s all linear ;
-webkit-transform : translateX ( -320 px );
-ms-transform : translateX ( -320 px );
transform : translateX ( -320 px );
-webkit-transform : translateX ( 0 px );
-ms-transform : translateX ( 0 px );
transform : translateX ( 0 px );
.main-menu .toggle-link {
-webkit-align-self : flex-end ;
-ms-flex-item-align : end ;
@media screen and ( min-width : 500 px ) {
For the off-canvas to function, we will write a click event, that triggers an active class to display the menu or hide it.
$ ( document ). ready ( function () {
$ ( " .toggle-link " ). click ( function () {
$ ( " #menu " ). toggleClass ( " active " );
and that’s it. Super simple, really easy to customize.
Results for
Load More Results