Use images instead of radio buttons

后端 未结 8 1794
Happy的楠姐
Happy的楠姐 2020-11-22 16:47

If I have a radio group with buttons:

\"Image

... how can I show only images in the select option i

8条回答
  •  不要未来只要你来
    2020-11-22 17:16

    Images can be placed in place of radio buttons by using label and span elements.

       

    Radio button should be hidden,

    .customize-radio label > input[type = 'radio'] {
        visibility: hidden;
        position: absolute;
    }
    

    Image can be given in the span tag,

    .customize-radio label > input[type = 'radio'] ~ span{
        cursor: pointer;
        width: 27px;
        height: 24px;
        display: inline-block;
        background-size: 27px 24px;
        background-repeat: no-repeat;
    }
    .haha-img {
        background-image: url('hahabefore.png');
    }
    
    .kiss-img{
        background-image: url('kissbefore.png');
    }
    .tongueout-img{
        background-image: url('tongueoutbefore.png');
    }
    

    To change the image on click of radio button, add checked state to the input tag,

    .customize-radio label > input[type = 'radio']:checked ~ span.haha-img{
         background-image: url('haha.png');
    }
    .customize-radio label > input[type = 'radio']:checked ~ span.kiss-img{
        background-image: url('kiss.png');
    }
    .customize-radio label > input[type = 'radio']:checked ~ span.tongueout-img{
            background-image: url('tongueout.png');
    }
    

    If you have any queries, Refer to the following link, As I have taken solution from the below blog, http://frontendsupport.blogspot.com/2018/06/cool-radio-buttons-with-images.html

提交回复
热议问题