日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > CSS >内容正文

CSS

如何用纯 CSS 创作一盘传统蚊香

發(fā)布時間:2023/12/2 CSS 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 如何用纯 CSS 创作一盘传统蚊香 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

效果預覽

在線演示

按下右側(cè)的“點擊預覽”按鈕可以在當前頁面預覽,點擊鏈接可以全屏預覽。


https://codepen.io/comehope/pen/BVpvMz


可交互視頻教程


此視頻是可以交互的,你可以隨時暫停視頻,編輯視頻中的代碼。


請用 chrome, safari, edge 打開觀看。


https://scrimba.com/p/pEgDAM/cZ8Ebf7


源代碼下載


本地下載

每日前端實戰(zhàn)系列的全部源代碼請從 github 下載:


https://github.com/comehope/front-end-daily-challenges


代碼解讀


定義 dom,容器中包含 8 個子元素:

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

居中顯示:

body {margin: 0;height: 100vh;display: flex;align-items: center;justify-content: center;background: radial-gradient(circle at center, midnightblue, black); }

畫出紋香盤要用的框線:

.coil {position: relative;display: flex;justify-content: center; }.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(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; }

把一半框線放置到上方:

.coil span:nth-child(odd) {align-self: flex-end; }

刪除掉上方框線的下邊框,和下方框線的上邊框:

.coil span:nth-child(odd) {border-bottom: none; }.coil span:nth-child(even) {border-top: none; }

對齊上下邊框:

.coil span:nth-child(even) {transform: translateX(-1em); }

把邊框改為曲線:

.coil span:nth-child(odd) {border-radius: 50% 50% 0 0 / 100% 100% 0 0; }.coil span:nth-child(even) {border-radius: 0 0 50% 50% / 0 0 100% 100%; }

用偽元素畫出蚊香最中間的部分:

.coil::before {content: '';position: absolute;width: 1em;height: 1em;background-color: darkgreen;border-radius: 50%;left: -1.5em;top: -0.5em; }

用偽元素畫出蚊香的燃點:

.coil::after {content: '';position: absolute;width: 1em;height: 1em;border-radius: 50%;top: -0.5em;background-color: darkred;left: -9.5em;z-index: -1;transform: scale(0.9);box-shadow: 0 0 1em white; }

最后,為燃點增加閃動的效果:

.coil::after {animation: blink 1s linear infinite alternate; }@keyframes blink {to {box-shadow: 0 0 0 white;} }

大功告成!

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


更多專業(yè)前端知識,請上 【猿2048】www.mk2048.com

總結(jié)

以上是生活随笔為你收集整理的如何用纯 CSS 创作一盘传统蚊香的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。