html - 切换开关不适用于 safari 和 chrome,但适用于 Firefox

标签 html css 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 函数被成功调用。

最佳答案

然后正确复制粘贴。这一切都适用于我最新的 chrome。问题是什么?

关于html - 切换开关不适用于 safari 和 chrome,但适用于 Firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52662177/

相关文章:

html - IE8 重复包装 <pre> 标签中的文本

html - 单击它们时图像正在缩小

javascript阅读更多功能?

javascript - 有没有办法使用默认的 Word 或 PDF 图像/图标作为缩略图而不是通用的灰色背景?

css - 如何使用 html 加 css 设置 textarea 行和调整大小?

WPF 复选框控件不响应 MouseLeftButtonDown 事件

android - 根据选中状态更改 CheckBoxPreference 摘要

html - Angular 5 Material将跨度居中到垫头单元格中

html - 带圆 Angular 的三 Angular 形

jquery - jsTree 复选框 ajax 请求,已选中