5

enter image description here enter image description here

I made this thing with javascript to increment/decrement an input field. It has a hover state but it lacks a click state.

Is there a neat way to make a click state using only CSS?

E.g. darken the background slightly more for 0.1 sec on each click.

Browser compatible solutions preferred but not required.

2
  • please share with what you came up Commented Aug 23, 2014 at 21:43
  • 1
    I made a quick fiddle jsfiddle.net/x50hud0g Commented Aug 25, 2014 at 6:06

2 Answers 2

10

I believe the :active pseudo class is what you are after:

http://www.w3schools.com/cssref/sel_active.asp

A 0.1 sec delay could be achieved using CSS3 transitions, however using jQuery would be simpler and work across more browsers.

Sign up to request clarification or add additional context in comments.

Comments

2

The problem here is the "each click"!

It would be possible to "delegate" one state.

State one -> not clicked
State two -> clicked (by selector :active or :focus)

But if you want to have an increment / decrement functionality you must not use plain css.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.