html - Style bootsrap radio buttons via images -
i attempting style radio buttons using images, via background-color property. using bootstrap, code sequence looks this:
<div id="something"> <div class="radio"> <label> <input id="some_id" value="yes" type="radio"> yes </label> </div> <div class="radio"> <label> <input id="some_id2" checked="" value="no" type="radio"> no </label> </div> </div>
what want edit it's icons checked, unchecked, focused, checked-focused , disabled states. don't want text have background, icon in front of it.
css:
.radio label { line-height: 40px; min-height: 40px; } .radio label{ background-image: url("https://upload.wikimedia.org/wikipedia/commons/thumb/5/53/google_%22g%22_logo.svg/1024px-google_%22g%22_logo.svg.png"); background-size: 40px 40px; background-repeat: no-repeat; background-position: center; width: 40px; height: 40px; } .radio label:checked{ background-image: url("https://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/apple_logo_black.svg/170px-apple_logo_black.svg.png"); }
fiddle: https://jsfiddle.net/ql2wab24/
you can use css3 radio button styles,
radio{ position: reletive; overflow: hidden;} .radio label { line-height: 40px; min-height: 40px; } .radio label{ background-image: url("https://upload.wikimedia.org/wikipedia/commons/thumb/5/53/google_%22g%22_logo.svg/1024px-google_%22g%22_logo.svg.png"); background-size: 40px 40px; background-repeat: no-repeat; width: 40px; height: 40px; display: block; padding: 0 0 0 50px; } .radio input[type="radio"]:checked~label{ background-image: url("https://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/apple_logo_black.svg/170px-apple_logo_black.svg.png"); } .radio label:focus{ background-image: url("https://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/apple_logo_black.svg/170px-apple_logo_black.svg.png"); } .radio input[type="radio"]:checked~label:focus{ background-image: url("https://upload.wikimedia.org/wikipedia/commons/thumb/5/53/google_%22g%22_logo.svg/1024px-google_%22g%22_logo.svg.png"); } .radio input[type="radio"]{position: absolute;top: 0; left: 0; z-index: -1; opacity: 0; visibility: hidden;}
<div id="something"> <div class="radio"> <input id="some_id" value="yes" type="radio" name="name"> <label for="some_id"> yes </label> </div> <div class="radio"> <input id="some_id2" checked="" value="no" type="radio" name="name"> <label for="some_id2"> no </label> </div> </div>
Comments
Post a Comment