In CSS how do I style checkbox or radio button for pressed state apart from checked and not checked?

adithyag

I am using invisible radio buttons and checkboxes with visible labels to create mode UI (single mode active at any time) and toggle buttons respectively. Ideally I want to have a different image for each of the following states

  1. Unchecked
  2. Pressed
  3. Checked

I have used the following template. The :checked and :not(:checked) selectors are working. For buttons elements, :active seems to work for mouse down/pressed state. For checkboxes and radiobuttons, they don't seem to work. How do I do a style for just mouse down/pressed state?

    input#toggle_button:not(:checked) ~label{
      content: url(../assets/button_toggle_normal.png);
    }

    input#toggle_button:checked ~label{
      content: url(../assets/button_toggle_selected.png);
    }

    input#toggle_button:active ~label{
      content: url(../assets/button_toggle_pressed.png);
    }
Miguel Suarez

I dont think there would be a pure CSS solution to this, I would go and use Javascript / jQuery for this:

$("input#toggle_button ~label").on("mousedown", function(){
  $(this).addClass("pressed");
}).on("mouseup", function(){
  $(this).removeClass("pressed");
});

Check this Codepen: http://codepen.io/kaoz70/pen/JKWXvx

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I get which radio button is checked from a groupbox?

From Dev

How do I get which radio button is checked from a groupbox?

From Dev

How to retrieve radio button value from database in checked state in jsp

From Dev

How to get the text from radio button in a radio group when radio button checked state is changed

From Dev

How do I check if a radio button is checked using JavaScript?

From Dev

How do I change the name of a label if a specific radio button is checked?

From Dev

How do I check whether a user has 'checked' the checkbox & enable the submit button if checked else disable?

From Dev

How can I get the text of radio button if radio button checked?

From Dev

How to set checked="checked" in first radio button?

From Dev

How do I check if checkbox is checked in PHP?

From Dev

How do i check if a specific Radio button is checked among the other radio buttons using Javascript?

From Dev

How to reset a Kendo MVVM Radio Button's checked state?

From Dev

Checked radio button style sibling label

From Dev

Setting a radio button into session to retain checked state

From Dev

SWT CheckBox Button get checked/unchecked state

From Dev

Make sure button gets pressed if checked radio button change

From Dev

Using Laravel 4, how do I mark a radio button as checked if a session key is a specified value?

From Dev

How do I disable text areas based on what radio button is checked when the page loads?

From Dev

How do I get the checked radio button value using only React?

From Dev

Css style checkbox when not checked with jQuery validator

From Dev

How to set radio button to checked when i click on list item

From Dev

How can i keep the radio button checked and get the value

From Dev

How to set radio button to checked when i click on list item

From Dev

css checkbox not applying changes when in the :checked state

From Dev

How can I disable a button until a checkbox is checked?

From Dev

CSS for a checked radio button's label

From Dev

Android - How to enable a button if a radio button is checked?

From Dev

Customize checkbox checked style

From Dev

Checkbox state if not checked

Related Related

  1. 1

    How do I get which radio button is checked from a groupbox?

  2. 2

    How do I get which radio button is checked from a groupbox?

  3. 3

    How to retrieve radio button value from database in checked state in jsp

  4. 4

    How to get the text from radio button in a radio group when radio button checked state is changed

  5. 5

    How do I check if a radio button is checked using JavaScript?

  6. 6

    How do I change the name of a label if a specific radio button is checked?

  7. 7

    How do I check whether a user has 'checked' the checkbox & enable the submit button if checked else disable?

  8. 8

    How can I get the text of radio button if radio button checked?

  9. 9

    How to set checked="checked" in first radio button?

  10. 10

    How do I check if checkbox is checked in PHP?

  11. 11

    How do i check if a specific Radio button is checked among the other radio buttons using Javascript?

  12. 12

    How to reset a Kendo MVVM Radio Button's checked state?

  13. 13

    Checked radio button style sibling label

  14. 14

    Setting a radio button into session to retain checked state

  15. 15

    SWT CheckBox Button get checked/unchecked state

  16. 16

    Make sure button gets pressed if checked radio button change

  17. 17

    Using Laravel 4, how do I mark a radio button as checked if a session key is a specified value?

  18. 18

    How do I disable text areas based on what radio button is checked when the page loads?

  19. 19

    How do I get the checked radio button value using only React?

  20. 20

    Css style checkbox when not checked with jQuery validator

  21. 21

    How to set radio button to checked when i click on list item

  22. 22

    How can i keep the radio button checked and get the value

  23. 23

    How to set radio button to checked when i click on list item

  24. 24

    css checkbox not applying changes when in the :checked state

  25. 25

    How can I disable a button until a checkbox is checked?

  26. 26

    CSS for a checked radio button's label

  27. 27

    Android - How to enable a button if a radio button is checked?

  28. 28

    Customize checkbox checked style

  29. 29

    Checkbox state if not checked

HotTag

Archive