Custom pictures for checkbox?

情到浓时终转凉″ 提交于 2019-12-05 00:53:41

If you want it's with pure css solution then you have to add label in your markup . It's a trick & write lke this:

input[type=checkbox]{
    display:none;
}
input[type=checkbox] + label{
    height: 40px;
        width: 42px;
} 
body:not(#foo) input[type=checkbox]:checked + label{
    background-image: url("images/button-settings-normal.png");
} 

body:not(#foo) input[type=checkbox] + label{
    background-position:0 -46px; /* as per your requirement*/
    height: 40px;
}

HTML

<body>

<input type="checkbox" id="settingsbutton" class="button-settings"/>
<label for="settingsbutton"></label>

 </body>

Read these articles :

http://www.thecssninja.com/css/custom-inputs-using-css

http://www.wufoo.com/2011/06/13/custom-radio-buttons-and-checkboxes/

But it's not work in IE8 & below

See this link for styling check-boxes: http://ryanfait.com/resources/custom-checkboxes-and-radio-buttons/

The solution involves hiding the check-box and adding a styled element in place of it, which emulates the check-box's behavior.

Try this solution if you have some text in label

input[type=checkbox]{
    display:none;
}
input[type=checkbox] + label:before{
    height: 42px;
    width: 42px;
    content: url("../img/chk.jpg");
} 
body input[type=checkbox]:checked + label:before{
    content: url("../img/chk_checked.jpg");
} 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!