选中单选按钮只能工作一次

时间:2015-02-02 14:14:47

标签: html css radio-button

我在wordpress后循环中执行以下单选按钮代码:

<input id="<?php the_title(); ?>" type="radio" name="phoneSelect" value="test">
                 <label for="<?php the_title(); ?>">Select</label>

每个生成的单选按钮都有一个唯一的ID,它还为=&#34;&#34;分配了一个唯一的标签。当我执行以下样式时,checked元素仅在一个单选按钮上工作。当我选择另一个单选按钮时,第一个按钮会更改样式,但下一个单选按钮不会应用css设置

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

  input[type=radio] + label {
    display:inline-block;
    margin:-2px;
    padding: 4px 12px;
    margin-bottom: 0;
    font-size: 14px;
    line-height: 20px;
    color: #333;
    text-align: center;
    text-shadow: 0 1px 1px rgba(255,255,255,0.75);
    vertical-align: middle;
    cursor: pointer;
    background-color: #f5f5f5;
    background-image: -moz-linear-gradient(top,#fff,#e6e6e6);
    background-image: -webkit-gradient(linear,0 0,0 100%,from(#fff),to(#e6e6e6));
    background-image: -webkit-linear-gradient(top,#fff,#e6e6e6);
    background-image: -o-linear-gradient(top,#fff,#e6e6e6);
    background-image: linear-gradient(to bottom,#fff,#e6e6e6);
    background-repeat: repeat-x;
    border: 1px solid #ccc;
    border-color: #e6e6e6 #e6e6e6 #bfbfbf;
    border-color: rgba(0,0,0,0.1) rgba(0,0,0,0.1) rgba(0,0,0,0.25);
    border-bottom-color: #b3b3b3;
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff',endColorstr='#ffe6e6e6',GradientType=0);
    filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
    -webkit-box-shadow: inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05);
    -moz-box-shadow: inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05);
  }

  input[type=radio]:checked + label {
       background-image: none;
    outline: 0;
    -webkit-box-shadow: inset 0 2px 4px rgba(0,0,0,0.15),0 1px 2px rgba(0,0,0,0.05);
    -moz-box-shadow: inset 0 2px 4px rgba(0,0,0,0.15),0 1px 2px rgba(0,0,0,0.05);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.15),0 1px 2px rgba(0,0,0,0.05);
      background-color:#e0e0e0;
  }

以下JSfiddle可以复制该问题(显然是因为php没有被执行)http://jsfiddle.net/83uc5xy5/

1 个答案:

答案 0 :(得分:1)

这是一个有效的例子:

<div><input type="radio" name ="test" id="test"/>
    dasdas
</div>
<input type="radio" name ="test" id="test"/>

CSS:

input[type="radio"]:checked{
    margin-top:50px;
}

它将所选复选框从顶部移动50px。