Skip to content Skip to sidebar Skip to footer

How to create click events using CSS

An event is something that happens when we do something. The most common in CSS is the hover selector, which helps us select an element when we hover over it and then an event fires automatically. There is a way to avoid this, because in modern browsers there is a property called pointer event that we can disable. For example, if we have a connection and we set the value of the pointer-events property to none , it won't work:
Click here
Many use :target to make it work, but it's not always the best solution when it comes to skipping the behavior - click the link below to see what happens:

related to goals
Lorem ipsum dolor sit amet, élite adipiscing consectetur. Name eu cursus dui, ac fermentum eros. Interdum et malesuada fama ac ante ipsum primis in faucibus. Fusce elementum sapien and Augue fringilla aliquam. Ut a viverra libero, eget commodo nisi. Mecenas ultrices dignissim tenderness.

related to goals

Lorem ipsum dolor sit amet, élite adipiscing consectetur. Name eu cursus dui, ac fermentum eros. Interdum et malesuada fama ac ante ipsum primis in faucibus. Fusce elementum sapien and Augue fringilla aliquam. Ut a viverra libero, eget commodo nisi. Mecenas ultrices dignissim tenderness.
Another option is to use the :focus selector to expand hidden content with a single mouse click.
The advantage of this selector is that the page remains static, but we have to click somewhere "outside" to close the expanded content, and so the hidden content should be there immediately, with no intermediate tags:

Demo carefully
Lorem ipsum dolor sit amet, élite adipiscing consectetur. Name eu cursus dui, ac fermentum eros. Interdum et malesuada fama ac ante ipsum primis in faucibus. Fusce elementum sapien and Augue fringilla aliquam. Ut a viverra libero, eget commodo nisi. Mecenas ultrices dignissim tenderness.

Focus connection

Lorem ipsum dolor sit amet, élite adipiscing consectetur. Name eu cursus dui, ac fermentum eros. Interdum et malesuada fama ac ante ipsum primis in faucibus. Fusce elementum sapien and Augue fringilla aliquam. Ut a viverra libero, eget commodo nisi. Mecenas ultrices dignissim tenderness.
The last method is more elegant, although it requires more labels, but works better because it allows us to create a toggle effect, meaning it expands when clicked and collapses again when clicked. In this case we use the selector : checked :


Lorem ipsum dolor sit amet, élite adipiscing consectetur. Name eu cursus dui, ac fermentum eros. Interdum et malesuada fama ac ante ipsum primis in faucibus. Fusce elementum sapien and Augue fringilla aliquam. Ut a viverra libero, eget commodo nisi. Mecenas ultrices dignissim tenderness.





Lorem ipsum dolor sit amet, élite adipiscing consectetur. Name eu cursus dui, ac fermentum eros. Interdum et malesuada fama ac ante ipsum primis in faucibus. Fusce elementum sapien and Augue fringilla aliquam. Ut a viverra libero, eget commodo nisi. Mecenas ultrices dignissim tenderness.
Applying this effect to links you want to hide and expand with just one click is very simple: while creating a post, paste one of the codes above into the HTML box and replace the blue text with the name. your link and add your own text instead of green.

Post a Comment for "How to create click events using CSS"