为什么选中了这些复选框的单选按钮会跳? [英] Why do these checkbox-hacked radio buttons jump when they are selected?

查看:125
本文介绍了为什么选中了这些复选框的单选按钮会跳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用复选框标签hack为单选按钮添加类似于复选框的特殊样式。
我有两种复选框样式,常规和.angabe。

I'm using a checkbox label hack to add special checkbox-like styles for radio buttons. I have two checkbox styles, regular and .angabe.

您可以在 JSFiddle 中看到,选中.angabe收音机时,框跳上几个px。尝试了几种不同的顶部:位置没有很好的效果。有建议吗?

As you can see in the JSFiddle, when the .angabe radios are :checked, the boxes "jump" upwards by a few px. Have tried a few different top: positions to no good effect. Any suggestions?

这里是加价标记:

<div class="angabe">
    <input type="radio" value="1" id="ohne">
    <label for="ohne">Mit Angabe</label>
    <input type="radio" value="0" id="mit">
    <label for="mit">Ohne Angabe</label>
</div>

<div class="row">
    <input type="radio" id="pregnancy[1]"><label for="pregnancy[1]">Pregnancy 1</label>
    <input type="radio" name="[pregnancy]" value="3" id="pregnancy[3]"><label for="pregnancy[3]">Pregnancy 2</label>
    <input type="radio" name="[pregnancy]" value="3" id="pregnancy[5]"><label for="pregnancy[5]">Pregnancy 3</label>
</div>

和CSS(剥离了长渐变声明,但仍然很长):

And the CSS (stripped of the long gradient declarations, but still pretty long):

body:nth-of-type(1) input[type="radio"], body:nth-of-type(1) .module.forms .indicationbox input { 
    display: none; 
}

body:nth-of-type(1) input[type="radio"] + label     {
    position:relative;
    margin-left:20px;
}

body:nth-of-type(1) input[type="radio"] + label:after  {
    position:absolute;
    left:4px;
    top:7px;

    content: "\00a0"; /* character: space */
    height: 10px;
    width: 10px;
    display: inline-block;
    font-size: 12px;
    line-height: 14px;
    text-align: center;

    -webkit-box-shadow: inset 1px 2px 3px rgba(50, 50, 50, 0.5);
    -moz-box-shadow:    inset 1px 2px 3px rgba(50, 50, 50, 0.5);
    box-shadow:         inset 1px 2px 3px rgba(50, 50, 50, 0.5);

    background:#c6e0b3;
} 

body:nth-of-type(1) input[type="radio"] + label:before  {
    left:0px;
    top:0px;
    content: "\00a0"; /* character: space */
    height: 18px;
    width: 18px;
    margin-right:5px;
    display: inline-block;
    font-size: 12px;
    line-height: 16px;
    padding:0px;
    text-align: center;
    background-color: #ebd196;
    -webkit-box-shadow: 1px 2px 3px rgba(50, 50, 50, 0.5);
    -moz-box-shadow:    1px 2px 3px rgba(50, 50, 50, 0.5);
    box-shadow:         1px 2px 3px rgba(50, 50, 50, 0.5);
}

body:nth-of-type(1) input[type="radio"]:checked + label:after {
    content: "\02714"; /* character: tick mark */
}


/** Special Angabe radio styles **/ 
body:nth-of-type(1) .angabe input[type="radio"]:checked + label:before {
    top: 0px;
    left:0px;
    height: 11px;
    width: 11px;
    border: 4px solid #324b23;
    background: rgba(255,255,255,0.4);
}

body:nth-of-type(1) .angabe input[type="radio"]:checked + label:after {
    top: 6px;
    left:6px;
    width:7px;
    height:7px;
    background: #324b23; 
}

body:nth-of-type(1) .angabe input[type="radio"]:checked + label:after {
    content: "\00a0"; /* character: space */
}


推荐答案

尝试以下更改:

body:nth-of-type(1) input[type="checkbox"] + label:after, body:nth-of-type(1) input[type="radio"] + label:after {
top: 3px;
}
body:nth-of-type(1) input[type="checkbox"] + label:before, body:nth-of-type(1) input[type="radio"] + label:before {
position: relative;
top: -4px;
}
body:nth-of-type(1) .angabe input[type="radio"]:checked + label:before {
top: 1px;
margin-right: 4px;
}

JSFIDDLE

这篇关于为什么选中了这些复选框的单选按钮会跳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆