拨动开关css

时间:2017-07-24 07:59:59

标签: javascript jquery html css

我有div有3个div。

左右div是文本,中心div需要切换开关。

这是代码

 <div class="doctors-appointment">
            <div class="Row">
                <div class="Column">
                    <b>Doctor's appointment</b>
                </div>
                <div class="Column">
                    <label class="switch">
                        <input type="checkbox">
                        <span class="slider round"></span>
                    </label>
                </div>
                <div class="Column">
                    <b>For internal purposes</b>
                </div>
                </div>
            </div>

但切换开关不在div

这是屏幕:

enter image description here

我从那里获得样式w3school

这是div的css

.doctors-appointment {
    clear: both;
    width: 100%;
    margin-top: 100px;
    color: #1d69b4;
    font-size: 20px;
}
      .Row {
        display: table;
        width: 100%; /*Optional*/
        table-layout: fixed; /*Optional*/
        border-spacing: 10px; /*Optional*/
    }
    .Column {
        display: table-cell;
        background-color: red; /*Optional*/
    }

我的问题在哪里?

2 个答案:

答案 0 :(得分:1)

添加此CSS

&#13;
&#13;
.doctors-appointment {
    clear: both;
    width: 100%;
    margin-top: 100px;
    color: #1d69b4;
    font-size: 20px;
}
      .Row {
        display: table;
        width: 100%; /*Optional*/
        table-layout: fixed; /*Optional*/
        border-spacing: 10px; /*Optional*/
    }
    .Column {
        display: table-cell;
        background-color: red; /*Optional*/
    }

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

/* Hide default HTML checkbox */
.switch input {display:none;}

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

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

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

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

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

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

.slider.round:before {
  border-radius: 50%;
}
&#13;
<div class="doctors-appointment">
            <div class="Row">
                <div class="Column">
                    <b>Doctor's appointment</b>
                </div>
                <div class="Column">
                    <label class="switch">
                        <input type="checkbox">
                        <span class="slider round"></span>
                    </label>
                </div>
                <div class="Column">
                    <b>For internal purposes</b>
                </div>
                </div>
            </div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

您可以仅使用输入内容和某些样式进行制作,实际上并不需要新的跨度。

在这里,我使用sass上传一个codepen。

您的输入应类似于:

<input class="switch" type="checkbox" />

样式:

.switch{
  -webkit-appearance: none;
  height: 1rem;
  width: 3rem;
  background-color: gray;
  border-radius: 43px;
  position: relative;
  cursor: pointer;
  &::after {
    top: 1px;
    left: 2px;
    content: '';
    width: 0.8rem;
    height:0.8rem;
    background-color:lightgray;
    position: absolute;
    border-radius: 100%;
    transition: 1s;
  }
  &:checked {
    background-color: blue;
    &::after {
      transform: translateX(2rem);
    }
  }
  &:focus {
    outline-color: transparent;
  }
}

https://codepen.io/jdtorregrosas/pen/qLzvye