Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

Carlos Serrano
Carlos Serrano
3,351 Points

Responsive menu toggle

Hello everyone. I'm following the CSS Responsive Navigation Menu post from Treehouse's Blog:

http://blog.teamtreehouse.com/create-an-absolute-basic-mobile-css-responsive-navigation-menu

and was wondering how to make the menu display by clicking instead of :hover.

thank you,

2 Answers

Click events are really meant for javascript, not for css. onclick(someFunction) for javascript. I don't think there is a :click for css3 actually. However I may be wrong. I do know that you can create a hack by using a hidden checkbox and the :checked selector. but as far as click events go, that is better used for javascript.

Keith Kelly
Keith Kelly
21,326 Points

To expand on what Victor said although you can do somethings with css like animations, it's primary purpose of that language is styling. What you are looking for is a behavior which would be handles with JavaScript.

Each language you use to create web pages serves a specific purpose.

  • HTML for structure
  • CSS for styling
  • JavaScript for page behavior
Carlos Serrano
Carlos Serrano
3,351 Points

Thank you Victor and Kelly. I'll start experimenting with JS.

Jeremy Williams
Jeremy Williams
9,078 Points

You could try :active but that will only keep the menu open as long as the mouse button is pressed I believe.