隐藏复选框内的复选框

时间:2018-11-26 00:48:31

标签: html css css3 toggle

我要删除切换按钮内的复选框。当切换按钮处于打开或关闭状态时,我希望复选框被隐藏。

这是我的示例代码:

<div class="form-group has-feedback">
  <input id="wffm302ebacf2b634d59b0dc1e81e451bc8d_Sections_0__Fields_6__Id" name="wffm302ebacf2b634d59b0dc1e81e451bc8d.Sections[0].Fields[6].Id" type="hidden" value="{D7AB5D2E-444F-49C7-91E4-564496D7C8A2}">
  <div>
    <input data-val="true" data-val-required="The Value field is required." id="wffm302ebacf2b634d59b0dc1e81e451bc8d_Sections_0__Fields_6__Value" name="wffm302ebacf2b634d59b0dc1e81e451bc8d.Sections[0].Fields[6].Value" type="checkbox" value="true" autocomplete="off" style="display: none;">
    <span class="button-checkbox bootstrap-checkbox">
      <button type="button" class="btn clearfix custom-btn">
        <span class="icon fa fa-check theme-text" style="display:none;"></span>
        <span class="icon fa fa-check-square"></span>
        <span class="icon cb-icon-check-indeterminate" style="display:none;"></span>
      </button>
    </span>
    <label class="switch">
      <input name="wffm302ebacf2b634d59b0dc1e81e451bc8d.Sections[0].Fields[6].Value" type="checkbox" value="false">
      <span class="slider round"></span>
    </label>
  </div>
  <span class="field-validation-valid help-block" data-valmsg-for="wffm302ebacf2b634d59b0dc1e81e451bc8d.Sections[0].Fields[6].Value" data-valmsg-replace="true"></span>
</div>

Jsfiddle example

我尝试了几种CSS隐藏该复选框,但是它不起作用。我尝试过:

button.btn.clearfix.custom-btn{
    display:none
}

但这隐藏了页面上的所有复选框

2 个答案:

答案 0 :(得分:1)

您应该可以通过将以下内容添加到CSS中来解决此问题:

.switch button {
  display:none;
}

以下是一个工作示例,其中添加了以下CSS:

/* Add this */
.switch button {
  display:none;
}

.switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

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

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

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

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

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

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

.switchbtn:before {
    border-radius: 50%;
}
<label class="switch">
    <input class="switchbtn" data-val="true" data-val-required="The Value field is required." id="wffm302ebacf2b634d59b0dc1e81e451bc8d_Sections_0__Fields_6__Value" name="wffm302ebacf2b634d59b0dc1e81e451bc8d.Sections[0].Fields[6].Value" type="checkbox" value="true" autocomplete="off" style="display: none;" aria-invalid="false" aria-describedby="wffm302ebacf2b634d59b0dc1e81e451bc8d\.Sections\[0\]\.Fields\[6\]\.Value-error wffm302ebacf2b634d59b0dc1e81e451bc8d\.Sections\[0\]\.Fields\[6\]\.Value-error"><span class="button-checkbox bootstrap-checkbox switchbtn"><button type="button" class="btn clearfix custom-btn"><span class="icon fa fa-check theme-text" style="display: none;"></span><span class="icon fa fa-check-square" style="display: inline;"></span><span class="icon cb-icon-check-indeterminate" style="display:none;"></span></button></span><input name="wffm302ebacf2b634d59b0dc1e81e451bc8d.Sections[0].Fields[6].Value" type="hidden" value="false">
</label>

答案 1 :(得分:1)

在{strong之前仅添加.switch,以仅定位属于开关子级的按钮 (=在switch类下=)

  .switch button.btn.clearfix.custom-btn {
    display: none
  }

更新的代码:

  .switch {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 34px;
  }

  .switch input {
    opacity: 0;
    width: 0;
    height: 0;
  }

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

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

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

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

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

  /* Rounded sliders */

  .switchbtn {
    border-radius: 34px;
  }

  .switchbtn:before {
    border-radius: 50%;
  }

  .switch button.btn.clearfix.custom-btn {
    display: none
  }
<label class="switch">
  <input class="switchbtn" data-val="true" data-val-required="The Value field is required." id="wffm302ebacf2b634d59b0dc1e81e451bc8d_Sections_0__Fields_6__Value"
    name="wffm302ebacf2b634d59b0dc1e81e451bc8d.Sections[0].Fields[6].Value" type="checkbox" value="true" autocomplete="off"
    style="display: none;" aria-invalid="false" aria-describedby="wffm302ebacf2b634d59b0dc1e81e451bc8d\.Sections\[0\]\.Fields\[6\]\.Value-error wffm302ebacf2b634d59b0dc1e81e451bc8d\.Sections\[0\]\.Fields\[6\]\.Value-error">
  <span class="button-checkbox bootstrap-checkbox switchbtn">
    <button type="button" class="btn clearfix custom-btn">
      <span class="icon fa fa-check theme-text" style="display: none;">
      </span>
      <span class="icon fa fa-check-square" style="display: inline;"></span>
      <span class="icon cb-icon-check-indeterminate" style="display:none;"></span>
    </button>
  </span>
  <input name="wffm302ebacf2b634d59b0dc1e81e451bc8d.Sections[0].Fields[6].Value" type="hidden" value="false">
</label>

相关问题