48.纯 CSS 创作一盘传统蚊香

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

感想: 都是半圆边框合成的。

HTML code:

<div class="coil">
    <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{
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle at center, midnightblue, black);
}
.coil{
    position: relative;
    display: flex;
    justify-content: center;
}
.coil::before,
.coil::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    width: 1em;
    height: 1em;
    top: -0.5em;
}

/* 蚊香中间部分 */
.coil::before{
    left: -2em;
    background: darkgreen;
}
/* 蚊香的燃点 */
.coil::after{
    left: -10em;
    background: darkred;
    box-shadow: 0 0 1em white;
    transform: scale(0.9);
    box-shadow: 0 0 1em white;
    animation: blink 1.5s ease-in-out infinite alternate;
    z-index: -1;
}
@keyframes blink{
    to{
        box-shadow: 0 0 0 white;
    }
}
.coil span{
    position: absolute;
    width: calc((var(--n) * 2 -1) * 1em);
    height: calc((var(--n) -0.5) * 1em);
    border: 1em solid darkgreen;
}
/* 将一半框线放置上方 */
.coil span:nth-child(odd){
    align-self: flex-end;
    border-bottom: none;
    border-radius: 50% 50% 0 0 / 100% 100% 0 0 ;
}
.coil span:nth-child(even){
    border-top: none;
    /* 对齐上下边框 */
    transform: translateX(-1em);
    border-radius: 0 0 50% 50% / 0 0 100% 100%;
}
.coil span:nth-child(1){
    --n: 1;
}
.coil span:nth-child(2) {
    --n: 2;
}
.coil span:nth-child(3) {
    --n: 3;
}
.coil span:nth-child(4) {
    --n: 4;
}
.coil span:nth-child(5) {
    --n: 5;
}
.coil span:nth-child(6) {
    --n: 6;
}
.coil span:nth-child(7) {
    --n: 7;
}
.coil span:nth-child(8) {
    --n: 8;
}

 

posted on 2019-03-05 00:16  人生与戏 阅读( ...) 评论( ...) 编辑 收藏

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值