Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You'll want to put the radio buttons in <code>label</code>s and apply the background styling to the label primarily (you can also add styling to the radio buttons themselves, but remember that their text is a separate element). Unfortunately, since CSS doesn't have the <code>:contains</code> pseudo-class that was discussed at one point (because of performance concerns), you will be forced to throw a bit of JavaScript at it.</p> <p>Example (<a href="http://jsbin.com/ujibid" rel="nofollow">live copy</a>):</p> <p>CSS:</p> <pre><code>label.highlight { background-color: yellow; /* Or whatever, obviously */ } input[type=radio] { /* Styles you want applied to the radio buttons when *not* selected */ } label.highlight input[type=radio] { /* ...any styles you want applied to the radio button when it's selected; this is more broadly cross-compatible than :checked, sadly */ } </code></pre> <p>HTML:</p> <pre><code>&lt;label&gt;&lt;input type='radio' name='foo' value='1'&gt; One&lt;/label&gt; &lt;br&gt;&lt;label&gt;&lt;input type='radio' name='foo' value='2'&gt; Two&lt;/label&gt; &lt;br&gt;&lt;label&gt;&lt;input type='radio' name='foo' value='3'&gt; Three&lt;/label&gt; </code></pre> <p>JavaScript using jQuery:</p> <pre><code>jQuery(function($) { $("input:radio").click(function() { if (this.checked) { $("label.highlight").removeClass("highlight"); $(this).closest("label").addClass("highlight"); } }); }); </code></pre> <p>Obviously, you'll want to narrow those selectors a bit for your actual markup, as the above will apply to all radio buttons on the page...</p> <p>That works by styling the radio buttons themselves in one way when they aren't inside a <code>label</code> with class <code>highlight</code>, and a different way when they are. Then you simply toggle the <code>highlight</code> class on the <code>label</code> when the radio button is clicked, and CSS takes care of the rest, styling both the <code>label</code> (to get the background color/image) and the radio button (if you want to do fancy checkmarks).</p>
    singulars
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      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