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

歡迎訪問 生活随笔!

生活随笔

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

HTML

前端每日实战:66# 视频演示如何用纯 CSS 创作一台咖啡机

發布時間:2023/12/16 HTML 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 前端每日实战:66# 视频演示如何用纯 CSS 创作一台咖啡机 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

效果預覽

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

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

可交互視頻

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

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

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

源代碼下載

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

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

代碼解讀

定義 dom,容器中包含機體、出水口、咖啡杯、按鈕和咖啡:

<div class="coffee-machine"><span class="body"></span><span class="spout"></span><span class="cup"></span><span class="button"></span><span class="coffee"></span> </div>

居中顯示:

body {margin: 0;height: 100vh;display: flex;align-items: center;justify-content: center;background: linear-gradient(to right bottom, sandybrown, darkred); }

定義容器尺寸:

.coffee-machine {width: 15em;height: 15em;background-color: white;font-size: 20px;border-radius: 50%;border: 2em solid white; }

畫出機體的外框:

.coffee-machine {position: relative;display: flex;justify-content: center; }.body {position: absolute;width: 8em;height: 12em;background-color: sandybrown;border-radius: 1.2em;top: 1.5em;border-right: 0.6em solid peru; }

用偽元素畫出機體的中間部分:

.body::after {content: '';position: absolute;width: 8em;height: 8em;background-color: darkslategray;top: 2em;border-right: 0.6em solid black; }

畫出出水口:

.spout {position: absolute;width: 3em;height: 1em;background-color: white;top: 3.5em;border-radius: 0.5em;border-right: 0.5em solid silver; }

畫出咖啡杯的杯體:

.cup {position: absolute;width: 3em;height: 2em;background-color: white;bottom: 3.5em;border-radius: 0 0 1.4em 1.4em;border-right: 0.5em solid silver; }

用偽元素畫出咖啡杯的把手:

.cup::after {content: '';position: absolute;width: 0.6em;height: 0.6em;border: 0.3em solid silver;border-radius: 50%;right: -1.2em;top: 0.2em; }

畫出按鈕:

.button {position: absolute;width: 1.2em;height: 1.2em;background-color: tomato;border-radius: 50%;bottom: 2em;right: 4.5em; }

畫出咖啡:

.coffee::before, .coffee::after {content: '';position: absolute;width: 0.7em;height: 5em;background-color: chocolate;top: 4.5em;left: calc((15em - 0.7em) / 2); }

接下來潤色一下。

為咖啡機增加光影:

.coffee-machine {z-index: 1; }.coffee-machine::before, .coffee-machine::after {content: '';position: absolute;width: 2em;height: 2em;border: 0.3em solid transparent;z-index: 2;border-radius: 50%;border-left-color: white;left: 3.8em; }.coffee-machine::before {top: 1.8em;transform: rotate(40deg); }.coffee-machine::after {bottom: 1.8em;transform: rotate(-40deg); }

定義咖啡流動的前半段動畫,即咖啡從出水口流到杯中:

.coffee::before {animation: 2s linear infinite;animation-name: pouring-before;transform-origin: top; }@keyframes pouring-before {0%, 20% {transform: scaleY(0);}30%, 100% {transform: scaleY(1);}70%, 100% {visibility: hidden;} }

定義咖啡流動的后半段動畫,即出水口停止流出咖啡,剩余咖啡流到杯中:

.coffee::after {animation: 2s linear infinite;animation-name: pouring-after;transform-origin: bottom; }@keyframes pouring-after {0%, 70% {visibility: hidden;transform: scaleY(1);}80%, 100% {transform: scaleY(0);} }

大功告成!

總結

以上是生活随笔為你收集整理的前端每日实战:66# 视频演示如何用纯 CSS 创作一台咖啡机的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。