使单选按钮的整个背景可单击

时间:2017-02-13 08:00:03

标签: javascript jquery html css

您好我正在尝试使用单选按钮创建完全相同的东西 http://codepen.io/Athulks/pen/EZGpjZ

到目前为止,我已经达到了这个目标



.display_radio input[type="radio"] {
    background-color: #fed55c;
    border: 2px solid #fffdf6;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05), inset 0px -15px 10px -12px rgba(0,0,0,0.05);
    padding: 9px;
    margin: 36px 0 0 13px;
    -webkit-appearance: none;
    -moz-appearance: none;
    border-radius: 50px;
    display: inline-block;
    position: relative;
    float: left;
}
.money-radio-container span {
    margin: 35px 2px 0px 7px;
    font-size: 20px;
    font-weight: bold;
    float: left;
    color: #fff;
}
.display_radio {
    display: inline-block;
    line-height: 20px;
    margin-bottom: 10px;
    border: 1px solid #fed55c;
    width: 100px;
    height: 100px;
    border-radius: 100px;
    position: relative;
    text-align: center;
    vertical-align: middle;
    background-color: #fed55c;
}

<div class="col-md-12 money-radio-container">
    <div class="display_radio">
        <input type="radio" name="optradio" class="money-radio" value="10"><span>$ 10 </span>
    </div>
    <div class="display_radio">
        <input type="radio" name="optradio" class="money-radio" value="20"><span>$ 20 </span>
    </div>
    <div class="display_radio">
        <input type="radio" name="optradio" class="money-radio" value="50"><span>$ 50 </span>
    </div>
    <div class="display_radio">
        <input type="radio" name="optradio" class="money-radio" value="100"><span>$ 100 </span>
    </div>
    <div class="display_radio">
        <input type="radio" name="optradio" class="money-radio" value="150"><span>$ 150 </span>
    </div>
</div>
&#13;
&#13;
&#13;

如何使整个div可点击并从div中间删除该无线电图标。所以它看起来与我用按钮制作的第一个演示完全一样?

3 个答案:

答案 0 :(得分:3)

.display_radio input[type="radio"] {
    background-color: #fed55c;
    border: 2px solid #fffdf6;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05), inset 0px -15px 10px -12px rgba(0,0,0,0.05);
    padding: 9px;
    margin: 36px 0 0 13px;
    -webkit-appearance: none;
    -moz-appearance: none;
    border-radius: 50px;
    display: inline-block;
    position: relative;
    float: left;
}
.money-radio-container span {
    margin: 35px 2px 0px 7px;
    font-size: 20px;
    font-weight: bold;
    float: left;
    color: #fff;
}
.display_radio {
    display: inline-block;
    line-height: 20px;
    margin-bottom: 10px;
    border: 1px solid #fed55c;
    width: 100px;
    height: 100px;
    border-radius: 100px;
    position: relative;
    text-align: center;
    vertical-align: middle;
    background-color: #fed55c;
}
<div class="col-md-12 money-radio-container">
    <label class="display_radio">
        <input type="radio" name="optradio" class="money-radio" value="10"><span>$ 10 </span>
    </label>
    <label class="display_radio">
        <input type="radio" name="optradio" class="money-radio" value="20"><span>$ 20 </span>
    </label >
    <label class="display_radio">
        <input type="radio" name="optradio" class="money-radio" value="50"><span>$ 50 </span>
    </label >
    <label class="display_radio">
        <input type="radio" name="optradio" class="money-radio" value="100"><span>$ 100 </span>
    </label >
    <label class="display_radio">
        <input type="radio" name="optradio" class="money-radio" value="150"><span>$ 150 </span>
    </label >
</div>

答案 1 :(得分:2)

您需要使用标签标签而不是按钮

<div class="display_radio">
    <input type="radio" id="radio1" name="optradio" class="money-radio" value="10">
    <label for="radio1" class="btn btn-radiotype btn-circle" >$5</label>
</div>

然后你可以给'money-radio'类,显示:none,这样单选按钮就不会显示但它仍然可以正常工作。这些值仍将存储在相应的单选按钮中。

.money-radio {
  display:none;
}

答案 2 :(得分:-3)

你可以尝试像声音一样;

<a href='mypage'><div class="col-md-12 money-radio-container"></a>