Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.