CSS3,CSS对齐图像上的切换开关

时间:2012-07-19 02:42:46

标签: html css html5 css3

我将切换开关对准图像时遇到问题,这里是我需要的确切描述。 http://jsfiddle.net/9M4gc/,我的切换开关正在相应地工作,但我只需要使用CSS3来对齐图像上的切换开关。查看下面的图片。

这是我页面的当前外观: enter image description here

这是我想要的: enter image description here

这意味着我只想让切换开关在图像上,就像上面的图像一样。到目前为止,这是我的代码:

HTML:

<div class="back" id="toggle"><br/>
<img src="http://i1159.photobucket.com/albums/p637/Apulo_Cosmas/btn_push01c2x.png"/>
<label for="enjoy_web"></label>
<div class="slideThree">
<input type="checkbox" value="None" id="slideThree" name="check" />
<label for="slideThree"></label>
</div>
</div>

CSS:

body{
background:#088A08;
margin:auto;           
}


input[id=slideThree] {
visibility: hidden;
}

/* SLIDE THREE */
.slideThree {
width: 120px;
height: 45px;
background: #0101DF;

-webkit-border-radius: 30px;
-moz-border-radius: 30px;
border-radius: 30px;
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: 19px/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: 19px/26px Arial, sans-serif;
color: #fff;
position: absolute;
left: 10px;
z-index: 0;
font-weight: bold;
}

.slideThree label {
display: block;
width: 50px;
height: 40px;

-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 .10s ease;
cursor: pointer;
position: absolute;
top: 3px;
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: 68px;
}

可以在http://jsfiddle.net/9M4gc/查看工作演示,提前感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

为什么不将图像设置为背景,并将切换开关放在父div中?

以下是一个有效的例子:http://jsfiddle.net/529Lk/