0

我正在使用 CSS3 来设置像这个网站这样的复选框的样式(幻灯片三)

html:

<div class="slideThree">
        <input type="checkbox" id="slideThree" name="check" /> 
        <label for="slideThree"></label>
</div>

CSS:

input[type=checkbox] {
    visibility: hidden;
}

/* SLIDE THREE */
.slideThree {
    width: 91px;
    height: 26px;
    background: #2B3D61;
    margin: 5px;

    -webkit-border-radius: 50px;
    -moz-border-radius: 50px;
    border-radius: 50px;
    position: relative;

    -webkit-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,0.2);
    -moz-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,0.2);
    box-shadow: inset 0px 1px 1px rgba(0,0,0,0.5), 0px 1px 0px rgba(255,255,255,0.2);
}

.slideThree:after {
    content: 'OFF';
    font: 14px/26px Arial, sans-serif;
    color: #FFF;
    position: absolute;
    right: 10px;
    z-index: 0;
    font-weight: bold;
    text-shadow: 1px 1px 0px rgba(255,255,255,.15);
}

.slideThree:before {
    content: 'ON';
    font: 14px/26px Arial, sans-serif;
    color: #FFF;
    position: absolute;
    left: 10px;
    z-index: 0;
    font-weight: bold;
}

.slideThree label {
    display: block;
    width: 45px;
    height: 24px;

    -webkit-border-radius: 50px;
    -moz-border-radius: 50px;
    border-radius: 50px;

    -webkit-transition: all .4s ease;
    -moz-transition: all .4s ease;
    -o-transition: all .4s ease;
    -ms-transition: all .4s ease;
    transition: all .4s ease;
    cursor: pointer;
    position: absolute;
    top: 1px;
    left: 3px;
    z-index: 1;

    -webkit-box-shadow: 0px 2px 5px 0px rgba(0,0,0,0.3);
    -moz-box-shadow: 0px 2px 5px 0px rgba(0,0,0,0.3);
    box-shadow: 0px 2px 5px 0px rgba(0,0,0,0.3);
    background: #fcfff4;

    background: -webkit-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
    background: -moz-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
    background: -o-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
    background: -ms-linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
    background: linear-gradient(top, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fcfff4', endColorstr='#b3bead',GradientType=0 );
}

.slideThree input[type=checkbox]:checked + label {
    left: 44px;
}

IE8 在这里不支持某些东西。编辑我有一个DOCTYPE,我已经删除了z-index,但这没有改变。复选框仍然不起作用。有没有办法解决这个问题,还是我需要在我的 html 中使用条件 css?如果它降级为一个简单的复选框,对于 IE8 来说就可以了。

4

3 回答 3

1

解决这个问题的方法是为:afterand:before声明创建一个额外的类名,并使用 JavaScript 根据事件添加/删除这些类。

于 2013-05-08T17:33:50.977 回答
0

在标签之前和标签之后添加一个跨度:

<label for="slideThree"></label><span class="on">On</span><span class="off">Off</span>

.on 的 CSS:

font: 14px/26px Arial, sans-serif;
color: #FFF;
position: absolute;
left: 10px;
z-index: 0;
font-weight: bold;

.off 的 CSS:

font: 14px/26px Arial, sans-serif;
color: #FFF;
position: absolute;
right: 10px;
z-index: 0;
font-weight: bold;
text-shadow: 1px 1px 0px rgba(255,255,255,.15);
于 2013-05-08T17:36:15.233 回答
0

我使用脏(我的意思是拉斯维加斯脏)IE 有条件地覆盖 css 以将其恢复为一个复选框。

又名

<!--[if lt IE 9]> <link rel="stylesheet" href="default-ie.css" type="text/css" /> <![endif]-->
于 2013-05-08T20:53:45.987 回答