Responsive Navigation

This responsive nav scales irrespective of how many links you place in it and it doesn't use JavaScript to measure the menu's height. (JS is only used to toggle a class on the nav element to say whether it is visible or not). The animations in it are hardware accelerated on mobile phones. It doesn't leave a gap at the bottom of the document in the way that moving the whole page with translateY does. If you see a strange flash of white when toggling the navigation, that disappears when viewing the demo not inside of Codepen's iframe...

The technique is simple. It uses two block elements (I used a <div> inside a <nav> but it could just as easily have been a <ul> inside a <div> or whatever). CSS 3 transforms are used on the inner element to slide it up and down, as transforms will be hardware accelerated - this is mostly important for mobile. Use overflow: hidden on the outer element so that the inner one won't be visible when it's shifted up. The max-height of the outer element is toggled between 0px and 9999px. This happens faster than the animation on slide down, and slower on slide up, so the animation is visible on both occasions.

I'd prefer it if the content would slide down instead of toggling, so if you figure out a way to make that happen, be sure to let me know! Get in touch on Twitter @adrianosmond. A full explanation about to why I needed to do this can be found here.

Aliquam pulvinar laoreet risus. Sed malesuada condimentum auctor. Nullam porta, velit at sodales ultricies, lacus erat imperdiet tellus, porttitor eleifend ipsum quam nec ante. Nunc vitae neque quis augue accumsan posuere sit amet non odio. Morbi gravida iaculis lorem, non pharetra eros auctor eget. Pellentesque tellus mauris, facilisis quis consequat tincidunt, mollis vitae augue. Donec nec risus lobortis libero rhoncus ultricies eget sed nisl.

Donec varius lectus vel velit tempor imperdiet. Pellentesque sodales aliquet odio, non porttitor dolor vulputate nec. Ut malesuada, neque sit amet semper molestie, massa neque ultricies odio, id euismod libero nulla ac enim. Suspendisse potenti. Ut sem elit, congue non mattis sit amet, ullamcorper venenatis orci. Nunc in gravida purus. Ut vel tempor nunc. Etiam sed mollis ipsum. Nunc facilisis diam sed mi porttitor interdum. Morbi malesuada lectus id massa consectetur adipiscing. Proin hendrerit augue eget mi pharetra sed rutrum nulla mattis. In eleifend enim molestie erat fermentum euismod. Donec a vulputate augue. In hac habitasse platea dictumst. Nunc congue, felis non auctor pellentesque, sem augue suscipit elit, sollicitudin scelerisque libero erat eget diam.

Mauris a ligula at mauris feugiat accumsan ornare a velit. Pellentesque porttitor, urna eget sollicitudin cursus, urna elit auctor augue, non dictum tellus leo non dolor. Aenean vestibulum, dui faucibus placerat mollis, metus ante viverra risus, ut scelerisque lacus lectus id purus. Cras viverra risus nec quam tempor viverra. Vivamus accumsan aliquet sodales. Pellentesque orci urna, vehicula ut lacinia at, semper in urna. Suspendisse turpis erat, venenatis nec mollis nec, placerat ut metus. Vivamus ut orci lorem. Curabitur mollis tincidunt congue. Ut interdum felis a neque tristique bibendum. Sed vitae urna nisl, eget tincidunt est. Cras felis purus, pulvinar quis hendrerit non, sollicitudin vel metus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Ut elementum fermentum tortor, non feugiat lorem tempor consequat.