cssjquery-mobilejquery-mobile-radio

changing the Style of Radio buttons in jQuery mobile 1.4.0


I have the Following Radio buttons in my jQuery mobile app , I need to style them as the Radio button in the image bellow . I have tried the following css but it didn't give me the same result , Please Help me ..

enter image description here

Html

<div data-role="page">
<div data-role="header"  data-theme="b" style="height:63px;">
</div>
<div data-role="content">
    <form>
   <fieldset>
   <input type="radio"    id="Male"    value=" Male" name="radio-group-1" />
   <label  for="Male"  data-inline="true"  style="background:transparent                 !important;">Male </label>

   <input type="radio"    id="Female"    value=" Female" name="radio-group-1" />
   <label  for="Female"  data-inline="true" style="background:transparent !important;"   >Female </label>
    </fieldset> 
    </form>


 </div>
 </div>

CSS

input[type="radio"] {
display: none;
}


.ui-btn.ui-radio-off:after, .ui-btn.ui-radio-on:after{
   width: 25px;
   height: 25px;
 }

.ui-btn.ui-radio-off:after, .ui-btn.ui-radio-on:after{
   margin-top: -18px;
   margin-left: -38px; 
}
.ui-btn.ui-radio-on:after{
   width: 55px;
   height: 55px;
   background: green !important;
   background-size:100px 24px;
}

This is what i get enter image description here


Solution

  • To get a green inner circle with transparent around it and a border after that, you really need 2 circles. This could be achieved by adding a :before element as well as the :after element in CSS.

    Here is a DEMO

    The CSS makes the whole button 56px tall and vertically centers the text by making the line-height the same. When off, the radio image is 26x26 with a gray border. When on, the :before css adds a new 26x26 empty circle with a border while the :after css creates a smaller green circle in the center. NOTE: you may need to tweak sizes and margins to get your desired results.

    input[type="radio"] {
        display: none;
    }
    .ui-radio label {
        height:56px;
        line-height: 56px;
        padding-left: 50px;
    }
    .ui-radio .ui-btn.ui-radio-off:after {
        background-image: none;
        width: 26px;
        height: 26px;
        border: 2px solid #6E7983;
        margin-top: -13px;
    }
    .ui-radio .ui-btn.ui-radio-on:after {
        background-color: #86D51C;
        width: 14px;
        height: 14px;
        margin-top: -6px;
        margin-left: 10px;
        border: 0;
    }
    .ui-radio .ui-btn.ui-radio-on:before {
        content:"";
        position: absolute;
        display: block;
        border: 2px solid #6E7983;
        border-radius: 50%;
        background-color: transparent;
        width: 26px;
        height: 26px;
        margin-top: 14px;
        margin-left: -39px;
    }