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;
}

 

posted on 2019-04-08 10:22  人生与戏 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/FlyingLiao/p/10668942.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值