G
G
GoodProject2015-11-13 22:42:02
css
GoodProject, 2015-11-13 22:42:02

How to style type="checkbox" cross-browser?

Hello!

Please tell me how to make such a checkbox cross-browser:

Uh9A3AS.png

I tried in different ways, googled, but something did not work out very well.

There is only 1 checkbox on the page, but it is very nasty, so I have been racking my brain for more than an hour! :))

I will be very grateful to you for your help! :)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Defman21, 2015-11-13
@GoodProject

Make a label for the checkbox, hide the checkbox itself, add the necessary styles for the label through :before. (when checkbox:checked and checkbox are in the normal state, but the order of the tags in the code is important). A similar method was described on habrahabr.
Pseudocode:

<input type="checkbox" id="checkbox"><label for="checkbox">Test</label>
<style>
    #checkbox {
        display: none;
    }
    
    #checkbox:checked + label:before {
        content: "* ";
    }
    
    #checkbox + label:before {
        content: " ";
    }
</style>

Will display an asterisk for a checked checkbox and a checkmark for an empty checkbox. You just have to replace it all with pictures. Clicking on them will also work, because. :before :)

I
Ivan Kondratiev, 2015-11-13
@inik23

It is strange, of course, that, according to you, Gogle has a day off today).
Here's a heading in the right direction for the label

<labe for="test">Test</label>
<input type="чекбокс" id="test">

there is a cool "for" attribute that binds the field to a label,
try customizing the label

V
Victor, 2015-11-13
@master2016

Yes, they usually act in line with Defman21. A hidden checkbox and a div associated with it - and there you already shove whatever you want.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question