代码之家  ›  专栏  ›  技术社区  ›  Sudeep Ghimiray

如何在活动管理中添加切换输入按钮[[关闭]

  •  -3
  • Sudeep Ghimiray  · 技术社区  · 6 年前

    在我的一个模型上,我想在活动管理窗体中使用切换按钮而不是单选按钮。

    enter image description here

    我该怎么做?

    2 回复  |  直到 4 年前
        1
  •  2
  •   Piers C    6 年前
        2
  •  -1
  •   John Baker    6 年前

    您可以使用纯css使单选按钮显示为开关。搜索此 link 如果你想找到其他的选择。

    link 我在里面找到的代码 codepen.io

    .toggle {
      position: relative;
      height: 14px;
      width: 50px;
      border-radius: 15px;
      background: #ddd;
      margin: 8px 0;
    }
    
    .toggle input {
      opacity: 0;
      width: 100%;
      height: 200%;
      position: absolute;
      top: -7px;
      left: 0;
      z-index: 2;
      margin: 0
    }
    
    .toggle input:nth-child(2):checked {
      z-index: 1;
    }
    
    .toggle__pointer {
      position: absolute;
      top: -7px;
      left: 0;
      width: 28px;
      height: 28px;
      border-radius: 15px;
      background-color: #37b24d;
      -webkit-transition: left .15s ease-out;
      transition: left .15s ease-out;
    }
    
    .toggle input:nth-child(2):checked+.toggle__pointer {
      left: 22px;
      background-color: #495057;
    }
    <div class="toggle">
      <input type="radio" value="on" name="radio">
      <input type="radio" value="off" name="radio" checked>
      <div class="toggle__pointer"></div>
    </div>