美文网首页
样式(13&14) -- checkbox13&14

样式(13&14) -- checkbox13&14

作者: 卡拉咖啦 | 来源:发表于2019-10-30 00:06 被阅读0次

preview

demo预览

checkbox13

demo预览

checkbox14

description

scss

checkbox13:
/* html
<!-- checkboxWrapper主要用于定位 -->
<div class="checkboxWrapper">
  <div class="round">
    <input type="checkbox" value="" id="slideID" name="slide" checked>
    <label for="slideID"></label>
  </div>
</div>
*/

/* 如果想要方形按钮,把所有 border-radius 样式删除即可*/
$userScale: 1; /*建议通过改变这个值来调整按钮大小*/
$baseScale: 0.25;
$backgroundSize: 100px;/*兼容不同类型单位 vw, em, rem, px*/
$widthTimes: 3;
$switcherSizeTimes: 0.8;
$switchSpeech: 0.4s;
$checkboxBackgroundColor: #333;
$colorON: #27ae60;
$colorOFF: #000;
$backgroundWidth: $widthTimes * $backgroundSize;
$switcherSize: $switcherSizeTimes * $backgroundSize;

@mixin positionCenter {
  display: block;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.checkboxWrapper {
  font-size: inherit;
  height: 1em;
  width: 1em;
  position: relative;

  & .round {
    @include positionCenter;
    width: $backgroundSize;
    height: $backgroundSize;
    background-color: $checkboxBackgroundColor;
    position: absolute;
    transform: translate(-50%, -50%) scale(calc(#{$baseScale} * #{$userScale}));
    border-radius: 50%;
    background: #fcfff4;
    background: linear-gradient(to bottom, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
    box-shadow: inset 0px 5px 5px white, 0px 5px 15px rgba(0, 0, 0, 0.5);

    & label {
      @include positionCenter;
      border-radius: 50%;
      height: 0.73 * $backgroundSize;
      width: 0.73 * $backgroundSize;
      z-index: 1;
      background: linear-gradient(to bottom, #222222 0%, #45484d 100%);
      box-shadow: inset 0px 5px 5px rgba(0, 0, 0, 0.5), 0px 4px 0px white;
      cursor: pointer;
      overflow: hidden;

      &::after {
        @include positionCenter;
        content: "";
        width: 0.58 * $backgroundSize;
        height: 0.58 * $backgroundSize;
        z-index: 2;
        margin-top: -1px;
        margin-left: -1px;/*这两个用于调节视觉效果*/
        background: #27ae60;
        background: linear-gradient(to bottom, #27ae60 0%, #145b32 100%);
        opacity: 0;
        border-radius: 50px;
        box-shadow: inset 0px 4px 4px white, 0px 4px 15px rgba(0, 0, 0, 0.5)
      }
      &:hover::after {
        opacity: 0.3;
      }
    }
}

  & input[type=checkbox] {
    visibility: hidden;
    &:checked + label:after {
      opacity: 1;
    }
  }
}

* {
  box-sizing: border-box;
  padding: 0;
  margin: 0;
}
body {
  background: #3498db;
}
checkbox14

<!-- checkboxWrapper主要用于定位 -->
<div class="checkboxWrapper">
  <div class="round">
    <input type="checkbox" value="" id="slideID" name="slide" checked>
    <label for="slideID"></label>
  </div>
</div>

$userScale: 1;/*建议通过改变这个值来调整按钮大小*/
$baseScale: 0.25;
$backgroundSize: 100px;/*兼容不同类型单位 vw, em, rem, px*/
$widthTimes: 3;
$switcherSizeTimes: 0.8;
$switchSpeech: 0.4s;
$checkboxBackgroundColor: #333;
$iconColor: #fcfff4;
$backgroundWidth: $widthTimes * $backgroundSize;
$switcherSize: $switcherSizeTimes * $backgroundSize;

@mixin positionCenter {
  display: block;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.checkboxWrapper {
  font-size: inherit;
  height: 1em;
  width: 1em;
  position: relative;

  & .round {
    @include positionCenter;
    transform:translate(-50%, -50%) scale(calc(#{$baseScale} * #{$userScale}));
    width: $backgroundSize;
    height: $backgroundSize;
    background-color: $checkboxBackgroundColor;
    border-radius: 50%;
    background: #fcfff4;
    background: linear-gradient(to bottom, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
    box-shadow: inset 0px 5px 5px white, 0px 5px 15px rgba(0, 0, 0, 0.5);

    & label {
      @include positionCenter;
      border-radius: 50%;
      height: 0.73 * $backgroundSize;
      width: 0.73 * $backgroundSize;
      z-index: 1;
      background: linear-gradient(to bottom, #222222 0%, #45484d 100%);
      box-shadow: inset 0px 5px 5px rgba(0, 0, 0, 0.5), 0px 4px 0px white;
      cursor: pointer;
      overflow: hidden;

      &::after {
        display: block;
        position: absolute;
        left: 13px;
        top: 17px;
        content: "";
        box-sizing: border-box;
        width: 0.5 * $backgroundSize;
        height: 0.3 * $backgroundSize;
        border: 12px solid $iconColor;
        border-top: none;
        border-right: none;
        transform: rotate(-45deg);
        z-index: 2;
        margin-top: -1px;
        margin-left: -1px;/*这两个用于调节视觉效果*/
        opacity: 0;
      }
      &:hover::after {
        opacity: 0.3;
      }
    }

    & input[type=checkbox] {
      visibility: hidden;
      &:checked + label:after {
        opacity: 1;
      }
    }
  }
}

* {
  box-sizing: border-box;
}
body {
  background: #3498db;
}

相关文章

  • 样式(13&14) -- checkbox13&14

    preview demo预览 demo预览 description scss checkbox13: checkb...

  • Beyond Feelings - Chapter 13&14

    Vocabulary interfaith n. 不同宗教信仰者(间)的,不同宗教团体(间)的 derelicti...

  • 100天40本-第13&14周-小结(完成)

    100天40本-第13&14周-小结 首先,自我反省:第12周完成36本书后,又想着马上会有国庆8天大假,读书时间...

  • 高效写作笔记(七)

    第七天 章节13&14 掌握论断分寸的第二个要领,如何使论断成为金句: 1、在文章段落的开头使用强有力的动词。(动...

  • 《浪潮之巅》13&14章

    阅读12章的时候,看到了硅谷创业者的艰辛和随IT浪潮一路发展的不易。14章从投资者的角度介绍了创业者的幕后英雄风险...

  • CSS-基础

    选择器样式:背景/大小样式:文本/字体 选择器 样式:背景/大小 样式:文本/字体 样式:边框 样式:内边距 样式...

  • CSS哪些样式属性可以继承

    不可继承的样式 可继承的样式 所有元素可继承: 内联样式: 块状样式: 列表样式: 表格样式:

  • iOS 改变字符串中所有指定字符串的颜色

    样式 代码 样式 代码 样式

  • CSS修饰

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

  • React Native StryleSheet 实践总结

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

网友评论

      本文标题:样式(13&14) -- checkbox13&14

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