Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom images as radio buttons
    primarykey
    data
    text
    <p>I have been trying to make custom radio buttons using HTML, CSS, and JavaScript. I've been looking through the previous questions about radio buttons and I feel like I've implemented the suggestions, but my jpeg images are still being cut in half. I'm clearly missing something, but not sure what it is. Below is my HTML CSS and JavaScript. Any input would be greatly appreciated. </p> <pre><code>&lt;style TYPE="text/css"&gt; .has-js .label_check, .has-js .label_radio { padding-left: 40px;} .has-js .label_radio { background: url(images/radio_button-21.jpg) no-repeat; width: 33px; height: 35px;} .has-js .label_check { background: url(check-off.png) no-repeat; } .has-js label.c_on { background: url(check-on.png) no-repeat; } .has-js label.r_on { background: url(images/radio_button_selected.jpg) no-repeat; width: 33px; height: 35px;} .has-js .label_check input, .has-js .label_radio input { position: absolute; left: -9999px;} &lt;/style&gt; &lt;/head&gt; &lt;label class="label_radio" for="radio-01"&gt; &lt;input name="sample-radio" id="radio-01" value="1" type="radio" /&gt; Yes &lt;/label&gt; &lt;br /&gt; &lt;br /&gt; &lt;label class="label_radio" for="radio-02"&gt; &lt;input name="sample-radio" id="radio-02" value="2" type="radio" /&gt; No &lt;/label&gt; &lt;br /&gt; &lt;br /&gt; &lt;label class="label_radio" for="radio-03"&gt; &lt;input name="sample-radio" id="radio-03" value="3" type="radio" /&gt; Maybe &lt;/label&gt; &lt;/body&gt; </code></pre> <p>JavaScript Code</p> <pre><code>onload = function() { var body = gebtn(d,'body')[0]; body.className = body.className &amp;&amp; body.className != '' ? body.className + ' has-js' : 'has-js'; if (!d.getElementById || !d.createTextNode) return; var ls = gebtn(d,'label'); for (var i = 0; i &lt; ls.length; i++) { var l = ls[i]; if (l.className.indexOf('label_') == -1) continue; var inp = gebtn(l,'input')[0]; if (l.className == 'label_check') { l.className = (safari &amp;&amp; inp.checked == true || inp.checked) ? 'label_check c_on' : 'label_check c_off'; l.onclick = check_it; }; if (l.className == 'label_radio') { l.className = (safari &amp;&amp; inp.checked == true || inp.checked) ? 'label_radio r_on' : 'label_radio r_off'; l.onclick = turn_radio; }; }; }; var check_it = function() { var inp = gebtn(this,'input')[0]; if (this.className == 'label_check c_off' || (!safari &amp;&amp; inp.checked)) { this.className = 'label_check c_on'; if (safari) inp.click(); } else { this.className = 'label_check c_off'; if (safari) inp.click(); }; }; var turn_radio = function() { var inp = gebtn(this,'input')[0]; if (this.className == 'label_radio r_off' || inp.checked) { var ls = gebtn(this.parentNode,'label'); for (var i = 0; i &lt; ls.length; i++) { var l = ls[i]; if (l.className.indexOf('label_radio') == -1) continue; l.className = 'label_radio r_off'; }; this.className = 'label_radio r_on'; if (safari) inp.click(); } else { this.className = 'label_radio r_off'; if (safari) inp.click(); }; }; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload