CSS3代码实现switch滑动开关按钮效果

直接上代码:
css

.my_switch {
  display: none;
}
.my_switch+label {
  display: inline-block;
  box-sizing: border-box;
  height: 20px;
  min-width: 60px;
  line-height: 16px;
  vertical-align: middle;
  border-radius: 100px;
  border: 1px solid transparent;
  background-color: rgba(0, 0, 0, 0.25);
  cursor: pointer;
  -webkit-transition: all 0.36s;
  transition: all 0.36s;
  position: relative;
}

.my_switch:checked+label {
  background-color: #1890ff;
}

.my_switch+label::before {
  content: "";
  display: block;
  width: 18px;
  height: 18px;
  position: absolute;
  left: 1px;
  top: 0;
  border-radius: 18px;
  background-color: #fff;
  cursor: pointer;
  transition: all 0.36s cubic-bezier(0.78, 0.14, 0.15, 0.86);
  -webkit-transition: all 0.36s cubic-bezier(0.78, 0.14, 0.15, 0.86);
  -webkit-box-shadow: 0 2px 4px 0 rgba(0, 35, 11, 0.2);
  box-shadow: 0 2px 4px 0 rgba(0, 35, 11, 0.2);
}

.my_switch:checked+label::before {
  left: 39px;
  transition: all 0.36s cubic-bezier(0.78, 0.14, 0.15, 0.86);
  -webkit-transition: all 0.36s cubic-bezier(0.78, 0.14, 0.15, 0.86);
}

.my_switch+label::after {
  content: "关";
  position: absolute;
  top: 1px;
  left: 24px;
  font-size: 12px;
  color: #fff
}

.my_switch:checked+label::after {
  content: "开";
  left: 5px;
}

标签


 

实现效果图:

在这里插入图片描述

你可能感兴趣的:(css)