CSS开/关开关不会更改基础复选框输入

时间:2016-06-24 20:47:15

标签: javascript html css

我有一个bootstrap.css,使用forchecked属性。这些开关似乎有效 - 即状态发生变化,开关也会生效 - 但隐藏复选框input上的基础<div class="onoff-container"> <div class="onoffswitch"> <input id="notify-by-slack" class="onoffswitch-checkbox" type="checkbox" name="survey[notify_by_slack]"> <label class="onoffswitch-label" for="notify-by-slack"> <span class="onoffswitch-inner"></span> <span class="onoffswitch-switch"></span> </label> </div> <p class="name"> Slack </p> </div> <div class="onoff-container"> <div class="onoffswitch"> <input id="notify-by-email" class="onoffswitch-checkbox" type="checkbox" name="survey[notify_by_email]"> <label class="onoffswitch-label" for="notify-by-email"> <span class="onoffswitch-inner"></span> <span class="onoffswitch-switch"></span> </label> </div> <p class="name"> Email </p> </div> 属性不会发生变化。

CSS on/off switch - 在开/关开关上执行“检查元素”以查看基础输入。

这是我的HTML:

.onoffswitch {
  position: relative;
  width: 90px;
  -webkit-user-select:none;
  -moz-user-select:none;
  -ms-user-select: none;
  display: inline-block;
}

.onoffswitch-checkbox {
  display: none;
}

.onoffswitch-label {
  display: block; overflow: hidden; cursor: pointer;
  border: 2px solid rgba(0, 0, 0, 0); border-radius: 20px;
}

.onoffswitch-inner {
  display: block; width: 200%; margin-left: -100%;
  transition: margin 0.3s ease-in 0s;
}

.onoffswitch-inner:before, .onoffswitch-inner:after {
  display: block; float: left; width: 50%; height: 30px; padding: 0; line-height: 30px;
  font-size: 14px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
  box-sizing: border-box;
}

.onoffswitch-inner:before {
  content: "ON";
  padding-left: 10px;
  background-color: #00C671; color: #FFFFFF;
}

.onoffswitch-inner:after {
  content: "OFF";
  padding-right: 10px;
  background-color: #EEEEEE; color: #999999;
  text-align: right;
}

.onoffswitch-switch {
  display: block; width: 18px; height: 18px; margin: 6px;
  background: #FFFFFF;
  position: absolute; top: 0; bottom: 0;
  right: 56px;
  border: 2px solid rgba(0, 0, 0, 0); border-radius: 20px;
  transition: all 0.3s ease-in 0s;
}

.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
  margin-left: 0;
}

.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
  right: 0px;
}

.onoff-container p.name {
  display: inline-block;
  position: relative;
  bottom: 11px;
}

这是我的CSS:

{{1}}

非常感谢任何帮助!提前谢谢!

0 个答案:

没有答案