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

Is there a way to trigger an event 'on click' in CSS?

I have an accordion using just HTML and CSS. Each tab bar includes a title and an arrow pointing down.

I want the arrow to rotate 180 degrees when I open the accordion.

I can do this 'on hover' but can't figure out how to trigger it 'on click'.

Any ideas? :)

1 Answer

kevin curtis
kevin curtis
15,287 Points

If you want to use pure css to trigger an event, you can affect an element temporarily when you click it by using the active pseudo class. But the effect will only last while you click. Alternatively you can use a checkbox hack. That involves creating the effect you want while the checkbox is ticked, and reverting to the previous state once it's unticked. Just google css checkbox hack. There are plenty of examples around the web.