我正在为平板电脑开发一个网络应用程序,我为我的复选框设计了一套div和一个标签,这样它看起来就像一个开关。(JsFiddle在这里。)
它在iPad 2& 3上工作得很好,但是当我在三星Galaxy 2上看到它时,它只在我将平板电脑从纵向转向景观时才会改变状态,反之亦然。
我也尝试过没有过渡,但仍然是同样的问题。
没有Javascript,我能得到我想要的效果吗?
所以不会让我链接到jsfiddle,下面是代码:
HTML:
<label class="switch" for="test">
<input type="checkbox" id="test">
<div class="track">
<div class="knob"></div>
</div>
</label>CSS:
label.switch > .track {
width: 80px;
height: 52px;
border-radius: 60px;
box-shadow: 0 1px 3px black inset, 0 -1px 1px rgba(255,255,255,0.15);
/*border: 5px solid #666;*/
display:inline-block;
cursor:pointer;
background: #333;
background: -moz-linear-gradient(top, rgba(0,0,0,0.65) 0%, rgba(0,0,0,0) 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0.65)), color-stop(100%,rgba(0,0,0,0)));
background: -webkit-linear-gradient(top, rgba(0,0,0,0.65) 0%,rgba(0,0,0,0) 100%);
background: -o-linear-gradient(top, rgba(0,0,0,0.65) 0%,rgba(0,0,0,0) 100%);
background: -ms-linear-gradient(top, rgba(0,0,0,0.65) 0%,rgba(0,0,0,0) 100%);
background: linear-gradient(to bottom, rgba(0,0,0,0.65) 0%,rgba(0,0,0,0) 100%);
transition: background .5s;
-webkit-transition: background .5s;
-moz-transition: background .5s;
-o-transition: background .5s;
-ms-transition: background .5s;
}
label.switch > .track > .knob {
height: 54px;
width: 54px;
border-radius: 50px;
margin-top:-1px;
box-shadow: 0 2px 3px black, 0 1px 0 rgba(255, 255, 255, 0.5) inset, 0 0 0 5px rgba(237,237,237,1) inset;
transition: margin-left .25s;
-webkit-transition: margin-left .25s;
-moz-transition: margin-left .25s;
-o-transition: margin-left .25s;
-ms-transition: margin-left .25s;
background: rgb(191,191,191);
background: -moz-linear-gradient(top, rgba(191,191,191,1) 0%, rgba(246,246,246,1) 53%, rgba(255,255,255,1) 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(191,191,191,1)), color-stop(53%,rgba(246,246,246,1)), color-stop(100%,rgba(255,255,255,1)));
background: -webkit-linear-gradient(top, rgba(191,191,191,1) 0%,rgba(246,246,246,1) 53%,rgba(255,255,255,1) 100%);
background: -o-linear-gradient(top, rgba(191,191,191,1) 0%,rgba(246,246,246,1) 53%,rgba(255,255,255,1) 100%);
background: -ms-linear-gradient(top, rgba(191,191,191,1) 0%,rgba(246,246,246,1) 53%,rgba(255,255,255,1) 100%);
background: linear-gradient(to bottom, rgba(191,191,191,1) 0%,rgba(246,246,246,1) 53%,rgba(255,255,255,1) 100%);
}
label.switch > input {
display:none;
}
label.switch > input:checked ~ .track {
background: #D96200
}
label.switch > input:checked ~ .track > .knob {
margin-left:26px;
}
https://stackoverflow.com/questions/13146526
复制相似问题