Is it possible to create an onclick effect instead of hover using css | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Is it possible to create an onclick effect instead of hover using css

24th Oct 2020, 6:09 AM
Francisco Bensaia
Francisco Bensaia - avatar
2 Answers
+ 5
Yes it is possible with the focus pseudo-class: <html> <head> <style type="text/css"> #hidden { display: none; border: 2px solid green; cursor: default; } a {text-decoration: none;} /* unvisited link */ a, div:visited { color: blue; } a:focus #hidden { color: black; display: block; } </style> </head> <body> <a href="#">Click to show box <div id="hidden">More information!<br/>Click outside to remove</div> </a> </body> </html>
24th Oct 2020, 6:20 AM
Alphin K Sajan
Alphin K Sajan - avatar
+ 1
Mercury Man Use active in place of hover And u got a click effect https://code.sololearn.com/WLUdrflVj1To/?ref=app
24th Oct 2020, 6:38 AM
Abhay
Abhay - avatar