美文网首页
样式(3) -- checkbox3

样式(3) -- checkbox3

作者: 卡拉咖啦 | 来源:发表于2019-10-18 17:25 被阅读0次

preview

demo预览

checkbox3.png

description

1.可自定义:
按钮大小 : checkboxSize,支持 em, rem, vw, px
宽高比 : checkboxWidthTimes
内容大小 : checkboxFontSizeTimes
动画时长 : SwitchingTime
按钮内容 : checkboxContentForOFF / checkboxContentForON
按钮背景 : checkboxBackgroundForOFF / checkboxBackgroundForOFF

2.label 使用 transform: skew(-10deg) 倾斜;label::afterlabel::after 使用 transform: skew(10deg) 抵消倾斜;

3.line-height 属性设置在 label 元素中,这样,如果我们使用 em 单位进行计算的时候,在 label::after 中动态设置 font-size 不会干扰 line-height 的计算。

scss

/* html
<div class="checkboxWrapper">
    <input type="checkbox" value="" id="slideID" name="slide" checked>
    <label for="slideID"></label>
</div>
*/

* { padding: 0; margin: 0; box-sizing: border-box; }
*::after{ box-sizing: border-box; }
*::before{ box-sizing: border-box; }

$checkboxSize: 2em;
$checkboxWidthTimes: 2;
$checkboxFontSizeTimes: 0.5;
$checkboxFontFamily: sans-serif;
$checkboxBackgroundForOFF: #888;
$checkboxBackgroundForON: #86d993;
$SwitchingTime: 0.2s;
$checkboxContentForOFF: "OFF";
$checkboxContentForON: "ON";

$checkboxWidth: $checkboxWidthTimes * $checkboxSize;
$checkboxFontSize: $checkboxFontSizeTimes * $checkboxSize;

.checkboxWrapper {
  & label {
    font-size: inherit;
    display: block;
    width: $checkboxWidth;
    height: $checkboxSize;
    background-color: $checkboxBackgroundForOFF;
    transform: skew(-10deg);
    position: relative;
    overflow: hidden;
    transition: all $SwitchingTime ease;
    line-height: $checkboxSize;

    &::before, &::after {
      content: $checkboxContentForOFF;
      font-family: $checkboxFontFamily;
      font-size: $checkboxFontSize;
      font-size: 1em;
      color: white;
      font-weight: bold;
      text-align: center;
      position: absolute;
      transition: all $SwitchingTime ease;
      left: 0px;
      top: 0px;
      width: 100%;
      height: 100%;
      transform: skew(10deg);
    }
    &::after {
      left: 100%;
      content: $checkboxContentForON;
    }
  }
  & input:checked {
    & + label {
      background-color: $checkboxBackgroundForON;

      &::before {
        left: -100%;
      }

      &::after {
        left: 0;
      }
    }
  }

  & input {
    display: none;
  }
}

相关文章

  • 样式(3) -- checkbox3

    preview demo预览 description 1.可自定义:按钮大小 : checkboxSize,支持 ...

  • React Native StryleSheet 实践总结

    1) 引入样式 2) 创建样式 3) 调用样式的几种方式 单个样式引用(对象) 多个样式引用(数组) 条件样式 ...

  • word13

    题目 3.修改字样式 展开发现没有标题3:点击样式右下角→在显示的样式竖栏最下行,点击第3个:管理样式。→推荐→选...

  • Photoshop样式:31个3D字体样式

    3D字体ps样式-Photoshop样式:31个3D字体样式- Mac下载为您推荐一套31个3D字体样式,您可以在...

  • day07(表单)

    布局 样式1内联样式(不用) 2内部样式 *{} 3外部样式

  • CSS的三种嵌入方式

    1.行内样式 2.页内样式 3.外部样式

  • react-native样式表写法

    1.内嵌样式 2.对象样式 3.内部样式 4.外部样式 5.混合样式

  • CSS修饰

    1. 内部样式 2. 内联样式 3. 引用外部样式 内部样式如下: 内联样式如下: 引用外部样式 优先级:内联样式...

  • 三.1、CSS样式引入方式

    CSS样式引入方式 1、内部样式: 2、外部样式表: 3、嵌入样式: 4、导入样式: link 和 @import...

  • css基础1

    使用css的方式 使用css的方式有3种,样式的优先权为:行内样式>内部样式>外部样式行内样式内部样式外部样式 行...

网友评论

      本文标题:样式(3) -- checkbox3

      本文链接:https://www.haomeiwen.com/subject/bdhwmctx.html