html - 添加值以翻转切换开关

标签 html css jquery-mobile jquery-mobile-flipswitch

我有这个翻转开关,如何更改为是或否。但是我可以将绿色更改为红色,但是向其中添加文本对我来说确实具有挑战性。如何向此 slider 添加文本。当绿色出现时应该是,当红色出现时应该是否。 我需要像链接中给出的这样的开关 https://drive.google.com/file/d/0B9lIGoSQI3nHQVhJd1k4UDhGU0k/view?usp=sharing

<style>
  .cmn-toggle {
    position: absolute;
    margin-left: -9999px;
    visibility: hidden;
  }
  .cmn-toggle + label {
    display: block;
    position: relative;
    cursor: pointer;
    outline: none;
    user-select: none;
  }
  input.cmn-toggle-round + label {
    padding: 2px;
    width: 120px;
    height: 60px;
    background-color: #dddddd;
    border-radius: 60px;
  }
  input.cmn-toggle-round + label:before,
  input.cmn-toggle-round + label:after {
    display: block;
    position: absolute;
    top: 1px;
    left: 1px;
    bottom: 1px;
    content: "";
  }
  input.cmn-toggle-round + label:before {
    right: 1px;
    background-color: #f1f1f1;
    border-radius: 60px;
    transition: background 0.4s;
  }
  input.cmn-toggle-round + label:after {
    width: 58px;
    background-color: #fff;
    border-radius: 100%;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    transition: margin 0.4s;
  }
  input.cmn-toggle-round:checked + label:before {
    background-color: #8ce196;
  }
  input.cmn-toggle-round:checked + label:after {
    margin-left: 60px;
  }

 HTML code:

    <div class="switch">
      <input id="cmn-toggle-1" class="cmn-toggle cmn-toggle-round" type="checkbox">
      <label for="cmn-toggle-1"></label>
    </div>

最佳答案

你只需要在勾选是和否时更改“内容”即可

.cmn-toggle {
    position: absolute;
    margin-left: -9999px;
    visibility: hidden;
  }
  .cmn-toggle + label {
    display: block;
    position: relative;
    cursor: pointer;
    outline: none;
    user-select: none;
  }
  input.cmn-toggle-round + label {
    padding: 2px;
    width: 120px;
    height: 60px;
    background-color: #dddddd;
    border-radius: 60px;
  }
  input.cmn-toggle-round + label:before,
  input.cmn-toggle-round + label:after {
    display: block;
    position: absolute;
    top: 1px;
    left: 1px;
    bottom: 1px;
      text-align:center;
  }
  input.cmn-toggle-round + label:before {
    right: 1px;
    background-color: #f1f1f1;
    border-radius: 60px;
    transition: background 0.4s;
  }
  input.cmn-toggle-round + label:after {
    width: 58px;
    background-color: #fff;
    border-radius: 100%;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    transition: margin 0.4s;
      line-height:390%;
      content:"NO";
  }
  input.cmn-toggle-round:checked + label:before {
    background-color: #8ce196;
      content:"";
  }
  input.cmn-toggle-round:checked + label:after {
    margin-left: 60px;
      content:"YES";
  }

.switch{
    display:flex;
    margin:auto;
}

关于html - 添加值以翻转切换开关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32912593/

相关文章:

javascript - CSS/Javascript : How to make rotating circular menu with multiple states?

javascript - 在视口(viewport)中按比例调整 DIV 的大小

javascript - 将 div 元素调整为原始大小, 'required' 大小

css - 有没有理由不在 CSS 中混合单位?

javascript - 通过javascript更新html表单中文本输入的背景颜色

css - 如何使用我们的用户定义样式覆盖默认的 Bootstrap.css 样式

javascript - JQuery Mobile showPageLoadingMsg 未按预期显示

iphone - 当 css 作为本地资源包含在 iPhone 上的 UIWebView 中时,jQuery Mobile Sprite 不显示

html - Bootstrap 3 中的行溢出其他内容

javascript - 覆盖网站上文本输入区域的默认移动设备键盘? (HTML/JS/jQuery)