怎么使用純CSS實現蚊香燃燒的效果?這個問題可能是我們日常學習或工作經常見到的。希望通過這個問題能讓你收獲頗深。下面是小編給大家帶來的參考內容,讓我們一起來看看吧!
站在用戶的角度思考問題,與客戶深入溝通,找到邯鄲網站設計與邯鄲網站推廣的解決方案,憑借多年的經驗,讓設計與互聯網技術結合,創造個性化、用戶體驗好的作品,建站類型包括:成都網站制作、成都做網站、外貿營銷網站建設、企業官網、英文網站、手機端網站、網站推廣、域名注冊、網頁空間、企業郵箱。業務覆蓋邯鄲地區。
每日前端實戰系列的全部源代碼請從 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; } }
感謝各位的閱讀!看完上述內容,你們對怎么使用純CSS實現蚊香燃燒的效果大概了解了嗎?希望文章內容對大家有所幫助。如果想了解更多相關文章內容,歡迎關注創新互聯行業資訊頻道。
標題名稱:怎么使用純CSS實現蚊香燃燒的效果
網站URL:http://m.2m8n56k.cn/article30/jdsjpo.html
成都網站建設公司_創新互聯,為您提供手機網站建設、網站導航、電子商務、網站維護、網站制作、建站公司
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯