简体   繁体   English

自定义CSS3复选框不适用于Firefox或IE

[英]Custom CSS3 Checkbox doesn't work on Firefox or IE

The Fiddle: http://jsfiddle.net/V98W8/ 小提琴: http//jsfiddle.net/V98W8/

I have a custom checkbox which looks and works perfectly in Chrome, but somehow in Firefox or IE shows up completely broken. 我有一个自定义复选框,在Chrome中看起来很完美,但在Firefox或IE浏览器中显示完全破碎。

I have tried adding custom prefixes and everything but it doesn't seem to solve the problem. 我已经尝试添加自定义前缀和一切,但它似乎没有解决问题。

#milestone-table input[type="checkbox"] {
    -webkit-appearance: none;
      -moz-appearance: none;
    appearance: none;
    background-color: #fafafa;
    border: 1px solid lightgrey;
    border-radius: 26px;

    -webkit-box-shadow: inset 0 0 0 1px lightgrey;
    box-shadow: inset 0 0 0 1px lightgrey;
    cursor: pointer;
    height: 28px;
    position: relative;

    -webkit-transition: border .25s .15s, box-shadow .25s .3s, padding .25s;
    -moz-transition: border .25s .15s, box-shadow .25s .3s, padding .25s;
    -o-transition: border .25s .15s, box-shadow .25s .3s, padding .25s;
    -ms-transition: border .25s .15s, box-shadow .25s .3s, padding .25s;
    transition: border .25s .15s, box-shadow .25s .3s, padding .25s;
    width: 54px;
    vertical-align: top;
    outline: none;
}

#milestone-table .controls input[type="checkbox"] {
    margin-top: 10px;
}

#add-milestone {
    position: relative;
    top: 7px;
    left: 90%;
}

#milestone-table {
    margin-top: -20px;
}

#milestone-table input[type="checkbox"]:after {
    background-color: white;
    border: 1px solid lightgrey;
    border-radius: 24px;

    -webkit-box-shadow: inset 0 -3px 3px rgba(0, 0, 0, 0.025), 0 1px 4px rgba(0, 0, 0, 0.15), 0 4px 4px rgba(0, 0, 0, 0.1);
    box-shadow: inset 0 -3px 3px rgba(0, 0, 0, 0.025), 0 1px 4px rgba(0, 0, 0, 0.15), 0 4px 4px rgba(0, 0, 0, 0.1);
    content: '';
    display: block;
    height: 24px;
    left: 0;
    position: absolute;
    right: 26px;
    top: 0;

    -webkit-transition: border .25s .15s, left .25s .1s, right .15s .175s;
    -moz-transition: border .25s .15s, left .25s .1s, right .15s .175s;
    -o-transition: border .25s .15s, left .25s .1s, right .15s .175s;
    -ms-transition: border .25s .15s, left .25s .1s, right .15s .175s;
    transition: border .25s .15s, left .25s .1s, right .15s .175s;
}

#milestone-table input[type="checkbox"]:checked {
    border-color: #53d76a;

    -webkit-box-shadow: inset 0 0 0 13px #53d76a;
    box-shadow: inset 0 0 0 13px #53d76a;
    padding-left: 18px;

    -webkit-transition: border .25s, box-shadow .25s, padding .25s .15s;
    -moz-transition: border .25s, box-shadow .25s, padding .25s .15s;
    -o-transition: border .25s, box-shadow .25s, padding .25s .15s;
    -ms-transition: border .25s, box-shadow .25s, padding .25s .15s;
    transition: border .25s, box-shadow .25s, padding .25s .15s;
}

#milestone-table input[type="checkbox"]:checked:after {
    border-color: #53d76a;
    left: 26px;
    right: 0;

    -webkit-transition: border .25s, left .15s .25s, right .25s .175s;
    -moz-transition: border .25s, left .15s .25s, right .25s .175s;
    -o-transition: border .25s, left .15s .25s, right .25s .175s;
    -ms-transition: border .25s, left .15s .25s, right .25s .175s;
    transition: border .25s, left .15s .25s, right .25s .175s;
}

Sadly, this is an old bug in Firefox that as far as I know hasn't been fixed. 可悲的是,据我所知,这是Firefox中的一个老版本,尚未修复。 If they haven't changed this very recently (which, judging from your problem, they haven't), styling checkboxes and radio buttons simply doesn't work properly in Firefox no matter what you do. 如果它们最近没有改变(从你的问题来看,它们没有改变),无论你做什么,样式复选框和单选按钮在Firefox中都无法正常工作。

Generally, a common way to work around this is by simply using regular divs and letting them toggle hidden fields through javascript or similar. 通常,解决此问题的常用方法是简单地使用常规div并让它们通过javascript或类似方法切换隐藏字段。 Absolutely not a pretty solution, but until they fix this bug, there's not much you can do. 绝对不是一个漂亮的解决方案,但在他们修复这个bug之前,你无能为力。

I made a quick example that uses a hidden checkbox and a label achieve something that works at least. 我做了一个快速示例 ,使用隐藏的复选框和标签实现至少有效的东西。 Of course, it isn't as pretty as merely using a regular input tag, but it should work in Firefox (and I guess IE, but I haven't tested). 当然,它不仅仅是使用常规输入标签,但它应该在Firefox中工作(我猜IE,但我还没有测试)。

<div id="milestone-table">
    <p>Checkbox</p>
    <label>
        <input type="checkbox"/>
        <label class="checkbox"/>
    </label>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM