I was trying to make a page that could in a single page (ie. a single .html file) display different contents depending on which buttons the user clicked. ie. if the user clicks "about" it shows them an about section. But it’s not the kind of page that you scroll down to see all contents, but rather, contents that are not currently activated/clicked are hidden/invisible. I need to do it in HTML/CSS only so I would need a trick.
I thought of using :active to do it but I don’t get how it works after all because this doesn’t work:
<style type="text/css">
#content {display: none;}
#content:active {display: block;}
</style>
<a href="#content">press here to show content</a>
<div id="content">
if pressed content is shown
</div>
In what way can I do it, then?
3
Answers
To achieve the menu popup functionality, you should prefer using the
checkbox input
of HTML alongside the:checked
CSS property.This would also help you to further add more functions w.r.t. the state of the input box, hence you will able to get an effect of
menu is open
ormenu is closed
as a propertyTry following the given example:
navbar, hide and show content on click
Using the :active pseudo-class isn’t the right approach for toggling visibility in the way you’re describing. Instead, you can use HTML anchor links and the :target pseudo-class to achieve this effect. Here’s how you can do it: