样式无线电输入问题

时间:2016-07-18 12:11:44

标签: html css forms input radio

我想设置无线电输入INSIDE"标签"标签。我已经改变了背景颜色,但是当我点击我的收音机时,里面的白点并没有显示出来。我为此编写了一个代码,我真的不知道问题所在。



<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <style>
      label {
        display: inline-block;
        cursor: pointer;
        position: relative;
        padding-left: 25px;
        margin-right: 15px;
        font-size: 13px;
        display:block;
      }

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

      label:before {
        content: "";
        display: inline-block;
        width: 17px;
        height: 17px;
        margin-right: 10px;
        position: absolute;
        left: 0;
        bottom: 1px;
        background-color: #ff7900;
        box-shadow: inset 0px 2px 3px 0px rgba(0, 0, 0, .3), 0px 1px 0px 0px rgba(255, 255, 255, .8);
        border-radius: 8px;
      }

      input[type=radio]:checked + label:before {
        content: "\2022";
        color: #f3f3f3;
        font-size: 30px;
        text-align: center;
        line-height: 18px;
        position: absolute;
      }

      .input {
        font-size: 20px;
        font-weight: bold;
      }
    </style>
  </head>
  <body>
    <form>
      <label class="input"><input type="radio" name="number" class="hehe">xxxxxxxx</label>
      <label class="input" ><input type="radio" name="number" class="hehe">xxxxxxx</label>
      <label class="input"><input type="radio" name="number" class="hehe">xxxxxxx</label>\
      <label class="input"><input type="radio" name="number" class="hehe">xxxxxxx</label>
    </form>
  </body>
</html>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:3)

此:

input[type=radio]:checked + label:before

要求label立即跟随输入。

但是,您的HTML是

 <label class="input"><input type="radio" name="number" class="hehe">xxxxxxxx</label>

标签环绕输入,因此选择器不起作用。

你需要

<input type="radio" name="number" class="hehe"/><label class="input">xxxxxxxx</label>

可替换地;在标签内的span上使用伪元素而不是标签本身

 <label class="input">
   <input type="radio" name="number" class="hehe">
   <span>xxxxxxxx</span>
 </label>

input[type=radio]:checked + span:before

答案 1 :(得分:-1)

您可以尝试使用此代码。 保利说的是对的。

&#13;
&#13;
label {
  display: inline-block;
  vertical-align: middle;
  margin-left: 30px;
  cursor: pointer;
}
input[type="radio"] {
  display: none;
}
input[type=radio] + label:before {
  content: '';
  width: 24px;
  height: 24px;
  background: tomato;
  border-radius: 50%;
  display: inline-block;
  vertical-align: middle;
  margin-right: 5px;
  z-index: 5;
  position: absolute;
  top: 0;
  left: 0;
}
input[type=radio]:checked + label:after {
  content: '';
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  display: inline-block;
  z-index: 10;
  position: absolute;
  top: 4px;
  left: 4px;
}
div {
  margin-bottom: 15px;
  position: relative;
}
&#13;
<div>
  <input type="radio" name="test" id="one">
  <label for="one">XXXXXXXXXXXX</label>
</div>
<div>
  <input type="radio" name="test" id="two">
  <label for="two">xxxx</label>
</div>
<div>
  <input type="radio" name="test" id="three" checked>
  <label for="three">xxxxxxxxxxxxx</label>
</div>
&#13;
&#13;
&#13;