【问题标题】::checked selector not working:checked 选择器不工作
【发布时间】:2015-08-14 16:20:56
【问题描述】:

我正在尝试让以下代码工作:

html

<div class = "col-md-4 video text-center wrapper-q1">
     <p class = "no-padding">
        <input class="question1" id = "vraag1" type="radio" name="q1" value="Moon"> <br />
        <label class = "pointer" for = "vraag1">Text</label>
     </p>
</div>

css

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

label:before {
    content: "";
    display: block;
    width: 33px;
    height:33px;
    margin:0 auto;
    background-image: url("../img/radio-btn.png");
}

input[type=radio]:checked + label {
    content: "";
    background-image: url("../img/radio-btn-checked.png");
    font-size: 30px;
    text-align: center;
    line-height: 18px;
}

显示单选按钮,但当我单击它时,它不会变为“选中”图像。

感谢您的帮助!

【问题讨论】:

    标签: html css input radio checked


    【解决方案1】:

    你错过了:before

    CSS:

    input[type=radio]:checked ~ label:before {
        content:"";
        background-image: url("../img/radio-btn-checked.png");
        font-size: 30px;
        text-align: center;
        line-height: 18px;
    }
    

    【讨论】:

    • 谢谢!但这似乎也不起作用:(还有其他想法吗?
    【解决方案2】:

    使用input[type=radio]:checked ~ label

    代替

    input[type=radio]:checked + label
    

    会为你工作。

    查看Fiddle

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-20
      • 1970-01-01
      • 2011-10-13
      • 1970-01-01
      • 2015-06-21
      • 1970-01-01
      相关资源
      最近更新 更多