zoukankan      html  css  js  c++  java
  • 68.纯 CSS 创作一本色卡

    原文地址:https://segmentfault.com/a/1190000015456554

    感想:复习下 transform-origin: 位置;

    HTML code:

    <div class="cards">
        <span></span>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
    </div>

    CSS code:

    html, body {
        margin: 0;
        padding: 0;
    }
    /* 设置body子元素水平垂直居中*/
    body {
        height: 100vh;
        display: flex;
        justify-content: center;
        align-items: center;
        background-color: lightgray;
    }
    /* 重定义盒模型 */
    .cards,
    .cards > * {
        /* width、height包括边框、内边距、内容区 */
        box-sizing: border-box;
    }
    /* 设置容器样式 */
    .cards {
        position: relative;
        font-size: 12px;
        width: 20em;
        height: 20em;
        /* border: 1px solid blue; */
    }
    /* 画出色卡 */
    .cards span{
        width: 10em;
        height: 3em;
        border: 0.2em solid dimgray; 
        border-radius: 0.3em 0.8em 0.8em 0.3em;
        /* 用 HSL 色彩模式为色卡上色 */
        background-color: hsl(calc(360 / 8 * var(--n)), 80%, 70%);
        position: absolute;
        top: calc(50% - 3em / 2);
        /* 定义动画效果,transform-origin定点绕其旋转 */
        transform-origin: right;
        animation: rotating 3s linear infinite;
        animation-delay: calc((var(--n) - 8) * 0.15s);
    }
    @keyframes rotating {
        0%, 35% {
            transform: rotate(0deg);
        }
    
        90%, 100% {
            transform: rotate(360deg);
        }
    }
    /* 用伪元素画出色卡的标签 */
    .cards span::before{
        content:'';
        width: 35%;
        height: 100%;
        border-left: 0.2em solid silver;
        border-radius: 0 0.6em 0.6em 0;
        background-color: white;
        position: absolute;
        right: 0;
    }
    .cards span::after {
        content: '';
        width: 0.4em;
        height: 2em;
        background-color: silver;
        position: absolute;
        left: 6.5em;
        top: 0.1em;
        box-shadow: 0.7em 0 0 -0.1em silver;
    }
    /* 为色卡设置变量 */
    .cards span:nth-child(1) {
        --n: 1;
    }
    .cards span:nth-child(2) {
        --n: 2;
    }
    .cards span:nth-child(3) {
        --n: 3;
    }
    .cards span:nth-child(4) {
        --n: 4;
    }
    .cards span:nth-child(5) {
        --n: 5;
    }
    .cards span:nth-child(6) {
        --n: 6;
    }
    .cards span:nth-child(7) {
        --n: 7;
    }
    .cards span:nth-child(8) {
        --n: 8;
    }
  • 相关阅读:
    构建之法阅读笔记01
    最长英语单词链
    第十五周学习总结
    寻找“水王”
    Happy Necklace HDU
    Bi-shoe and Phi-shoe LightOJ
    The Embarrassed Cryptographer POJ
    Big Number HDU
    矩阵乘法模板C/C++
    Baby Step,Giant Step算法模板
  • 原文地址:https://www.cnblogs.com/FlyingLiao/p/10668942.html
Copyright © 2011-2022 走看看