【问题标题】:How do I change the color and style of radio buttons如何更改单选按钮的颜色和样式
【发布时间】:2014-03-30 21:13:24
【问题描述】:

我有一个代码要修改,但它不起作用

HTML

<input type="radio" id="radio-1-1" name="radio-1-set" class="regular-radio" checked />

CSS

.regular-radio:checked:after {
    content: ' ';
    width: 12px;
    height: 12px;
    border-radius: 50px;
    position: absolute;
    top: 3px;
    background: #99a1a7;
    box-shadow: inset 0px 0px 10px rgba(0,0,0,0.3);
    text-shadow: 0px;
    left: 3px;
    font-size: 32px;
}
.regular-radio:checked {
    background-color: #e9ecee;
    color: #99a1a7;
    border: 1px solid #adb8c0;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05), inset 0px -15px 10px -12px rgba(0,0,0,0.05), inset 15px 10px -12px rgba(255,255,255,0.1), inset 0px 0px 10px rgba(0,0,0,0.1);
}

我需要像这样的单选框:-

让我知道我该怎么做?

谢谢。

【问题讨论】:

标签: html css


【解决方案1】:

在 css 中是可以的,但不是所有的浏览器都可以。

对所有浏览器的影响:

http://www.456bereastreet.com/lab/form_controls/checkboxes/

一种可能性是带有 javascript 的自定义复选框,例如:

http://ryanfait.com/resources/custom-checkboxes-and-radio-buttons/

【讨论】:

    【解决方案2】:

    你可以在没有 javascript 的情况下做到这一点。

    默认情况下,HTML 可以让您的标签触发输入。这意味着您可以隐藏您的输入,并在您的标签上放置一个 psudo 元素。通过这种方式,您可以设置您想要的任何单选按钮/复选框。 现在我没有测试下面的代码,把它应该接近这个。 顺便一提。没有在输入上显示 none 的原因是因为它使 IOS 崩溃,出于某种原因。

    <label for="test">
    <input type="radio" id="test" />
    </label>
    

    CSS

      input {
        position: absolute; 
        left: - 999em;
        }
            label {
            position relative;
            padding-left: 30px;
            }
            label:before {
            content: "";
            display: block;
    height: 10px;
    width: 10px;
            background: url(yourBackgroundImage.png) no-repeat 0 0;
            position: absolute;
            left: 0;
            top: 2px;
            }
    

    【讨论】:

      【解决方案3】:

      我认为它是一个圆形复选框。不是单选按钮。这是它是如何做到的。

      html

      <div class="roundedTwo">
          <input type="checkbox" value="None" id="roundedTwo" name="check" />
          <label for="roundedTwo"></label>
      </div>
      

      css

      body {
          background: #555;
      }
      input[type=checkbox] {
          visibility: hidden;
      }
      /* ROUNDED TWO */
      .roundedTwo {
          width: 28px;
          height: 28px;
          background: #fcfff4;
      
          background: -webkit-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
          background: -moz-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
          background: -o-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
          background: -ms-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
          background: linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
          filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fcfff4', endColorstr='#b3bead',GradientType=0 );
          margin: 20px auto;
      
          -webkit-border-radius: 50px;
          -moz-border-radius: 50px;
          border-radius: 50px;
      
          -webkit-box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5);
          -moz-box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5);
          box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0,0,0,0.5);
          position: relative;
      }
      
      .roundedTwo label {
          cursor: pointer;
          position: absolute;
          width: 20px;
          height: 20px;
      
          -webkit-border-radius: 50px;
          -moz-border-radius: 50px;
          border-radius: 50px;
          left: 4px;
          top: 4px;
      
          -webkit-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,1);
          -moz-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,1);
          box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,1);
      
          background: -webkit-linear-gradient(top, #222 0%, #45484d 100%);
          background: -moz-linear-gradient(top, #222 0%, #45484d 100%);
          background: -o-linear-gradient(top, #222 0%, #45484d 100%);
          background: -ms-linear-gradient(top, #222 0%, #45484d 100%);
          background: linear-gradient(top, #222 0%, #45484d 100%);
          filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#222', endColorstr='#45484d',GradientType=0 );
      }
      
      .roundedTwo label:after {
          -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
          filter: alpha(opacity=0);
          opacity: 0;
          content: '';
          position: absolute;
          width: 9px;
          height: 5px;
          background: transparent;
          top: 5px;
          left: 4px;
          border: 3px solid #fcfff4;
          border-top: none;
          border-right: none;
      
          -webkit-transform: rotate(-45deg);
          -moz-transform: rotate(-45deg);
          -o-transform: rotate(-45deg);
          -ms-transform: rotate(-45deg);
          transform: rotate(-45deg);
      }
      
      .roundedTwo label:hover::after {
          -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=30)";
          filter: alpha(opacity=30);
          opacity: 0.3;
      }
      
      .roundedTwo input[type=checkbox]:checked + label:after {
          -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
          filter: alpha(opacity=100);
          opacity: 1;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-05-14
        • 2016-09-11
        • 1970-01-01
        • 2021-11-20
        • 1970-01-01
        • 2014-05-27
        相关资源
        最近更新 更多