Toggle Switch在Safari和chrome上不起作用,但在Firefox中起作用

时间:2018-10-05 09:12:21

标签: html css css3 checkbox

我复制了https://www.w3schools.com/howto/howto_css_switch.asp中的代码,但在测试代码后,我发现它在Ubuntu / Mac / iOS上的Chrome和Safari(它们是最新版本)上不起作用。这是CSS代码:

 /* The switch - the box around the slider */
.switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}

/* Hide default HTML checkbox */
.switch input {display:none;}

/* The slider */
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  -webkit-transition: .4s;
  transition: .4s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  -webkit-transition: .4s;
  transition: .4s;
}

input:checked + .slider {
  background-color: #2196F3;
}

input:focus + .slider {
  box-shadow: 0 0 1px #2196F3;
}

input:checked + .slider:before {
  -webkit-transform: translateX(26px);
  -ms-transform: translateX(26px);
  transform: translateX(26px);
}

/* Rounded sliders */
.slider.round {
  border-radius: 34px;
}

.slider.round:before {
  border-radius: 50%;
}

另外,通过不工作,我的意思是当我切换复选框时,它不会更改颜色,或者实际上根本不会切换,但是链接的Js函数被成功调用。

1 个答案:

答案 0 :(得分:0)

然后正确复制粘贴。这一切对我来说都适用于我最新的Chrome。有什么问题吗?