伪元素定位问题

因为重写了radio的样式
所以用到了伪元素 但是不知道怎么调伪元素相对位置 像让radio和label垂直居中

clipboard.png

  <input type="radio" class="weui-check" name="phone">
                <label class="text-m">17601001839</label>
input[type="radio"] + label::before {
  content: '\a0';
  display: inline-block;
  width: .8em;
  height: .8em;
  border-radius: 50%;
  line-height: .5;
  box-shadow: 0 0 0 2px #959595 inset;
  margin: 0 10px 0 5px;
}

input[type="radio"]:checked + label::before {
  box-shadow: 0 0 0 4px #a6b8c7 inset;
  z-index: 2;
}
阅读 7k
2 个回答
label {
 position: relative
}
 label::before{
  position: absolute
  top:50%;
 left:0;
 transform: translateY(-50%);
/*知道高度的话也可以 margin:负高的一般*/
}
input[type="radio"] + label{
    position: relative
}
input[type="radio"] + label::before{
  position: absolute
}

不就好了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题