add an image to a html type input check box or radio

后端 未结 5 710
小鲜肉
小鲜肉 2020-12-03 20:24

I\'m trying to specify an image to be used for my unchecked and checked values for html input type checkbox and radio.

I have got this:

background: u         


        
5条回答
  •  广开言路
    2020-12-03 21:01

    Here is how I did it. I'm using radio input. The input boxes are hidden and the image in each label changes when the input is selected/not selected.

    Jsfiddle: http://jsfiddle.net/EhDsf/

    HTML:

    CSS:

    div.options > label > input {
        visibility: hidden;
    }
    
    div.options > label {
        display: block;
        margin: 0 0 0 -10px;
        padding: 0 0 48px 0;  
        height: 20px;
        width: 150px;
    
    }
    
    div.options > label > img {
        display: inline-block;
        padding: 0px;
        height:60px;
        width:60px;
        background: url(https://cdn2.iconfinder.com/data/icons/snipicons/500/thumbs-down-128.png);
        background-repeat: no-repeat;
        background-position:center center;
        background-size:60px 60px;
    }
    
    div.options > label > input:checked +img {  
        background: url(https://cdn1.iconfinder.com/data/icons/onebit/PNG/onebit_34.png);
        background-repeat: no-repeat;
        background-position:center center;
        background-size:60px 60px;
    }
    

提交回复
热议问题