How to change the size of the radio button using CSS?

前端 未结 14 1625
野的像风
野的像风 2020-11-28 06:17

Is there a way to control the size of the radio button in CSS ?

相关标签:
14条回答
  • 2020-11-28 06:48

    This works fine for me in all browsers:

    (inline style for simplicity...)

    <label style="font-size:16px;">
        <input style="height:1em; width:1em;" type="radio">
        <span>Button One</span>
    </label>
    

    The size of both the radio button and text will change with the label's font-size.

    0 讨论(0)
  • 2020-11-28 06:51

    You can also use the transform property, with required value in scale:

    input[type=radio]{transform:scale(2);}
    
    0 讨论(0)
  • 2020-11-28 06:51
    <html>
        <head>
        </head>
        <body>
    
    <style>
    .redradio {border:5px black solid;border-radius:25px;width:25px;height:25px;background:red;float:left;}
    .greenradio {border:5px black solid;border-radius:25px;width:29px;height:29px;background:green;float:left;}
    .radiobuttons{float:left;clear:both;margin-bottom:10px;}
    </style>
    <script type="text/javascript">
    <!--
    function switchON(groupelement,groupvalue,buttonelement,buttonvalue) {
        var groupelements = document.getElementById(groupelement);
        var buttons = groupelements.getElementsByTagName("button");
        for (i=0;i<buttons.length;i++) {
            if (buttons[i].id.indexOf("_on") != -1) {
                buttons[i].style.display="none";
            } else {
                buttons[i].style.display="block";
            }
        }
        var buttonON = buttonelement + "_button_on";
        var buttonOFF = buttonelement + "_button_off";
        document.getElementById(buttonON).style.display="block";
        document.getElementById(buttonOFF).style.display="none";
        document.getElementById(groupvalue).value=buttonvalue;
    }
    // -->
    </script>
    
    <form>
        <h1>farbige Radiobutton</h1>
        <div id="button_group">
            <input type="hidden" name="button_value" id="button_value" value=""/>
            <span class="radiobuttons">
                <button type="button" value="OFF1" name="button1_button_off" id="button1_button_off" onclick="switchON('button_group','button_value','button1',this.value)" class="redradio"></button>
                <button type="button" value="ON1" name="button1_button_on" id="button1_button_on" style="display:none;" class="greenradio"></button>
                <label for="button1_button_on">&nbsp;&nbsp;Ich will eins</label>
            </span><br/>
            <span class="radiobuttons">
                <button type="button" value="OFF2" name="button2_button_off" id="button2_button_off" onclick="switchON('button_group','button_value','button2',this.value)" class="redradio"></button>
                <button type="button" value="ON2" name="button2_button_on" id="button2_button_on" style="display:none;" class="greenradio"></button>
                <label for="button2_button_on">&nbsp;&nbsp;Ich will zwei</label>
            </span><br/>
            <span class="radiobuttons">
                <button type="button" value="OFF3" name="button3_button_off" id="button3_button_off" onclick="switchON('button_group','button_value','button3',this.value)" class="redradio"></button>
                <button type="button" value="ON3" name="button3_button_on" id="button3_button_on" style="display:none;" class="greenradio"></button>
                <label for="button3_button_on">&nbsp;&nbsp;Ich will drei</label>
            </span><br/>
            <span class="radiobuttons">
                <button type="button" value="OFF4" name="button4_button_off" id="button4_button_off" onclick="switchON('button_group','button_value','button4',this.value)" class="redradio"></button>
                <button type="button" value="ON4" name="button4_button_on" id="button4_button_on" style="display:none;" class="greenradio"></button>
                <label for="button4_button_on">&nbsp;&nbsp;Ich will vier</label>
            </span>
        </div>
    </form>
    
        </body>
    </html>
    
    0 讨论(0)
  • 2020-11-28 06:52

    try this code... it may be the ans what you exactly looking for

    body, html{
      height: 100%;
      background: #222222;
    }
    
    .container{
      display: block;
      position: relative;
      margin: 40px auto;
      height: auto;
      width: 500px;
      padding: 20px;
    }
    
    h2 {
    	color: #AAAAAA;
    }
    
    .container ul{
      list-style: none;
      margin: 0;
      padding: 0;
    	overflow: auto;
    }
    
    ul li{
      color: #AAAAAA;
      display: block;
      position: relative;
      float: left;
      width: 100%;
      height: 100px;
    	border-bottom: 1px solid #333;
    }
    
    ul li input[type=radio]{
      position: absolute;
      visibility: hidden;
    }
    
    ul li label{
      display: block;
      position: relative;
      font-weight: 300;
      font-size: 1.35em;
      padding: 25px 25px 25px 80px;
      margin: 10px auto;
      height: 30px;
      z-index: 9;
      cursor: pointer;
      -webkit-transition: all 0.25s linear;
    }
    
    ul li:hover label{
    	color: #FFFFFF;
    }
    
    ul li .check{
      display: block;
      position: absolute;
      border: 5px solid #AAAAAA;
      border-radius: 100%;
      height: 25px;
      width: 25px;
      top: 30px;
      left: 20px;
    	z-index: 5;
    	transition: border .25s linear;
    	-webkit-transition: border .25s linear;
    }
    
    ul li:hover .check {
      border: 5px solid #FFFFFF;
    }
    
    ul li .check::before {
      display: block;
      position: absolute;
    	content: '';
      border-radius: 100%;
      height: 15px;
      width: 15px;
      top: 5px;
    	left: 5px;
      margin: auto;
    	transition: background 0.25s linear;
    	-webkit-transition: background 0.25s linear;
    }
    
    input[type=radio]:checked ~ .check {
      border: 5px solid #0DFF92;
    }
    
    input[type=radio]:checked ~ .check::before{
      background: #0DFF92;
    }
    <ul>
      <li>
        <input type="radio" id="f-option" name="selector">
        <label for="f-option">Male</label>
        
        <div class="check"></div>
      </li>
      
      <li>
        <input type="radio" id="s-option" name="selector">
        <label for="s-option">Female</label>
        
        <div class="check"><div class="inside"></div></div>
      </li>
      
      <li>
        <input type="radio" id="t-option" name="selector">
        <label for="t-option">Transgender</label>
        
        <div class="check"><div class="inside"></div></div>
      </li>
    </ul>

    0 讨论(0)
  • 2020-11-28 06:53

    Directly you can not do this. [As per my knowledge].

    You should use images to supplant the radio buttons. You can make them function in the same manner as the radio buttons inmost cases, and you can make them any size you want.

    0 讨论(0)
  • 2020-11-28 06:54

    This css seems to do the trick:

    input[type=radio] {
        border: 0px;
        width: 100%;
        height: 2em;
    }
    

    Setting the border to 0 seems to allow the user to change the size of the button and have the browser render it in that size for eg. the above height: 2em will render the button at twice the line height. This also works for checkboxes (input[type=checkbox]). Some browsers render better than others.

    From a windows box it works in IE8+, FF21+, Chrome29+.

    0 讨论(0)
提交回复
热议问题