Putting css borders around radio buttons

前端 未结 7 1902
遥遥无期
遥遥无期 2020-12-01 14:37

I\'m trying to get a garish red border around some radio buttons, but it is not showing up in Firefox latest or Chrome latest. Work fine in IE9/IE8.

Each of the inp

相关标签:
7条回答
  • 2020-12-01 14:58

    Complete code using jquery

    https://jsfiddle.net/xcb26Lzx/

    $(function(){
          $('.layer').css('border',0);
        $('input:radio').change(
        function(){
            if ($(this).is(':checked')) {
                $('.layer').css('border','1px solid red');
            }
        });
    });
    
    0 讨论(0)
  • 2020-12-01 15:01

    Try this...

    Put a div around the input and assign a class to the div like so:

    <div class="custom"><input type="radio"></div>
    

    Then open your custom css file and add this CSS

    .custom {border: 1px solid red; border-radius: 30px; padding: 3px 3px 0 3px; background: red;}
    

    This should create a nice red border around the radio button. If you're using a check box you would simply remove the border-radius: 30px from the css. Depending you may need to play with the padding a bit to center the button, but this worked for me.

    Edit: You will also want to assign the following CSS to the div so it lines up correctly.

    .custom {display: inline;}
    

    fiddle link

    0 讨论(0)
  • 2020-12-01 15:04

    You could accomplish by wrapping each input element with div tag and give it a border and a float left... like this:

    <div style="border:1px solid red;float:left">
       <input type="radio".. />
    </div>
    No, I do not waive confidentiality
    
    0 讨论(0)
  • 2020-12-01 15:09

    This may help you:

    .style {
      border: 1px solid red;
      width: 20px;
      height: 20px;
      text-align: center;
      margin-top: 2px;
      background-color: #f0ffff;
    }
    <div class="style">
      <input type="radio" />
    </div>
    <div class="style">
      <input type="radio" />
    </div>
    <div class="style">
      <input type="radio" />
    </div>
    <div class="style">
      <input type="radio" />
    </div>

    View on JSFiddle

    0 讨论(0)
  • 2020-12-01 15:11
    input[type=radio]{
        outline: 1px solid red
    }
    
    0 讨论(0)
  • 2020-12-01 15:13

    I know this is four years old, but I came up with a nice solution using CSS Pseudo elements.

    My requirement was to highlight an unchecked checkbox, or radio button in validation.

    <input type="radio" class="required" name="radio1"/>
    
    /* Radio button and Checkbox .required needs an after to show */
    input[type=radio].required::after, input[type=checkbox].required::after {
        display: block;
        width: 100%;
        height: 100%;
        background: transparent;
        content: '';
        border: 2px solid red !important;
        box-sizing: border-box;
    }
    /* Radio buttons are round, so add 100% border radius. */
    input[type=radio].required::after {
         border-radius:100%;
    }
    
    0 讨论(0)
提交回复
热议问题