我用过Toggle Switch我需要在开关后面放上openclose开关标签,看看image 01image 02您可以理解我的问题,
这是显示为Openclosed Switch Open的两种类型,显示为open Switch Closed后显示为Closed,请查看工作片段
我该如何解决,
请帮我解决这个问题

谢谢

图片01-当前视图

css - 拨动开关标签-LMLPHP

图片02-我需要这样

css - 拨动开关标签-LMLPHP



 .onoffswitch1 {
    position: relative; width: 90px;
    -webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}

.onoffswitch1-checkbox {
    display: none;
}

.onoffswitch1-label {
    display: block; overflow: hidden; cursor: pointer;
    border: 2px solid #999999; border-radius: 30px;
}

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

.onoffswitch1-inner:before, .onoffswitch1-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;
    -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
    border-radius: 30px;
    box-shadow: 0px 15px 0px rgba(0,0,0,0.08) inset;
}

.onoffswitch1-inner:before {
    content: "YES";
    padding-left: 10px;
    background-color: #2FCCFF; color: #FFFFFF;
    border-radius: 30px 0 0 30px;
}

.onoffswitch1-inner:after {
    content: "NO";
    padding-right: 10px;
    background-color: #EEEEEE; color: #999999;
    text-align: right;
    border-radius: 0 30px 30px 0;
}

.onoffswitch1-switch {
    display: block; width: 30px; margin: 0px;
    background: #FFFFFF;
    border: 2px solid #999999; border-radius: 30px;
    position: absolute; top: 0; bottom: 0; right: 56px;
    -moz-transition: all 0.3s ease-in 0s; -webkit-transition: all 0.3s ease-in 0s;
    -o-transition: all 0.3s ease-in 0s; transition: all 0.3s ease-in 0s;
    background-image: -moz-linear-gradient(center top, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0) 80%);
    background-image: -webkit-linear-gradient(center top, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0) 80%);
    background-image: -o-linear-gradient(center top, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0) 80%);
    background-image: linear-gradient(center top, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0) 80%);
    box-shadow: 0 1px 1px white inset;
}

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

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

 <div class="onoffswitch1">
                  <input type="checkbox" name="onoffswitch1" class="onoffswitch1-checkbox" id="myonoffswitch1" checked>
                  <label class="onoffswitch1-label" for="myonoffswitch1">
                    <span class="onoffswitch1-inner"></span>
                    <span class="onoffswitch1-switch"></span>
                  </label>
                </div>

最佳答案

请检查这是否是您需要的。您可能需要调整文本的颜色和位置。



.onoffswitch1 {
  width: 90px;
}

.onoffswitch1-checkbox {
  display: none;
}

.onoffswitch1-label {
  display: inline-block;
  cursor: pointer;
  border: 2px solid #999999;
  border-radius: 30px;
  width: 90px;
  height: 2em;
  background: darkgray;
  position: relative;
  margin-top: 2em;
}

.onoffswitch1-checkbox:checked + .onoffswitch1-label {
  background: lightblue;
}

.onoffswitch1-checkbox:checked+.onoffswitch1-label:before {
  content: "OPEN";
  position: absolute;
  top: -1.5em;
  left: 0;
}

.onoffswitch1-checkbox+.onoffswitch1-label:before {
  content: "CLOSED";
  position: absolute;
  top: -1.5em;
  left: 0;
}

.onoffswitch1-switch {
  display: block;
  width: 30px;
  margin: 0px;
  background: #FFFFFF;
  border: 2px solid #999999;
  border-radius: 30px;
  position: absolute;
  top: 0;
  bottom: 0;
  right: 56px;
  -moz-transition: all 0.3s ease-in 0s;
  -webkit-transition: all 0.3s ease-in 0s;
  -o-transition: all 0.3s ease-in 0s;
  transition: all 0.3s ease-in 0s;
  background-image: -moz-linear-gradient(center top, rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0) 80%);
  background-image: -webkit-linear-gradient(center top, rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0) 80%);
  background-image: -o-linear-gradient(center top, rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0) 80%);
  background-image: linear-gradient(center top, rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0) 80%);
  box-shadow: 0 1px 1px white inset;
}

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

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

<div class="onoffswitch1">
  <input type="checkbox" name="onoffswitch1" class="onoffswitch1-checkbox" id="myonoffswitch1" checked>
  <label class="onoffswitch1-label" for="myonoffswitch1">
    <span class="onoffswitch1-inner"></span>
    <span class="onoffswitch1-switch"></span>
  </label>
</div>

关于css - 拨动开关标签,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45476774/

10-11 23:31
查看更多