這篇文章帶給大家的內容是關於如何使用純CSS實現大白的形象(附源碼),有一定的參考價值,有需要的朋友可以參考一下,希望對你有所幫助。
效果預覽
原始碼下載
https://github.com/comehope/front- end-daily-challenges
程式解讀
整個角色分為3 部分:頭、身體、腿,下面依照這個順序分別畫出,先畫頭部。
定義dom,容器.baymax
表示大白,head
表示頭部:
<div> <div> <div></div> </div> </div>
居中顯示:
body { margin: 0; height: 100vh; display: flex; align-items: center; justify-content: center; background-color: rgba(176, 0, 0, 0.75); }
定義容器尺寸和子元素對齊方式:
.baymax { width: 30em; height: 41em; font-size: 10px; display: flex; justify-content: center; position: relative; }
畫出頭部輪廓:
.head { position: absolute; width: 9em; height: 6em; background-color: white; border-radius: 50%; box-shadow: inset 0 -1.5em 3em rgba(0, 0, 0, 0.2), 0 0.5em 1.5em rgba(0, 0, 0, 0.2); }
畫出雙眼中間的線條:
.head .eyes { position: absolute; width: 4.8em; height: 0.1em; background-color: #222; top: 2.3em; left: calc((9em - 4.8em) / 2); }
畫出雙眼:
.head .eyes::before, .head .eyes::after { content: ''; position: absolute; width: 0.8em; height: 0.9em; background-color: #222; border-radius: 50%; top: -0.3em; } .head .eyes::after { right: 0; }
接下來畫身體。
html 檔案中增加身體的dom 元素:
<div> <div> <!-- 略 --> </div> <div> <div> <span></span> </div> <div></div> <div> <div></div> </div> <div> <div></div> </div> </div> </div>
定義身體的寬度:
.body { position: absolute; width: inherit; }
畫出胸部:
.body .chest { position: absolute; width: 19em; height: 26em; background-color: white; top: 4em; left: calc((100% - 19em) / 2); border-radius: 50%; z-index: -1; }
畫出胸前的按鈕:
.body .chest .button { position: absolute; width: 2em; height: 2em; background-color: white; border-radius: 50%; top: 4em; right: 4em; box-shadow: inset 0 -0.5em 0.8em rgba(0, 0, 0, 0.15), 0.2em 0.3em 0.2em rgba(0, 0, 0, 0.05); filter: opacity(0.75); }
畫出肚皮:
.body .belly { position: absolute; width: 24em; height: 31em; background-color: white; top: 5.5em; left: calc((100% - 24em) / 2); border-radius: 50%; z-index: -2; box-shadow: inset 0 -2.5em 4em rgba(0, 0, 0, 0.15), 0 0.5em 1.5em rgba(0, 0, 0, 0.25); }
定義手臂的高度起點:
.body .arm { position: absolute; top: 7.5em; }
手臂分為肘以上的部分和手肘以下的部分。
先設計這兩段的共有屬性:
.body .arm::before, .body .arm::after { content: ''; position: absolute; background-color: white; border-radius: 50%; transform-origin: top; z-index: -3; }
再用偽元素分別畫出這兩部分:
.body .arm::before { width: 9em; height: 20em; left: 7em; transform: rotate(30deg); } .body .arm::after { width: 8em; height: 15em; left: -0.8em; top: 9.5em; transform: rotate(-5deg); box-shadow: inset 0.4em -1em 1em rgba(0, 0, 0, 0.2); }
定義兩根手指的共有屬性:
.body .arm .fingers::before, .body .arm .fingers::after { content: ''; position: absolute; width: 1.8em; height: 4em; background-color: white; border-radius: 50%; transform-origin: top; }
用偽元素分別畫出兩根手指:
.body .arm .fingers::before { top: 22em; left: 2em; transform: rotate(-25deg); box-shadow: inset 0.2em -0.4em 0.4em rgba(0, 0, 0, 0.4); } .body .arm .fingers::after { top: 21.5em; left: 4.8em; transform: rotate(-5deg); box-shadow: inset -0.2em -0.4em 0.8em rgba(0, 0, 0, 0.3); z-index: -3; }
至此,完成了右手臂。把右手臂複製並水平翻轉,即可得到左手臂:
.body .arm.left { transform: scaleX(-1); right: 0; z-index: -3; }
接下來畫腿部。
在html 檔案中增加腿的dom 元素:
<div> <div> <!-- 略 --> </div> <div> <!-- 略 --> </div> <div></div> <div></div> </div>
畫出腿的內側:
.leg { position: absolute; width: 5em; height: 16em; bottom: 0; background-color: white; border-bottom-right-radius: 1.5em; left: 10em; box-shadow: inset -0.7em -0.6em 0.7em rgba(0, 0, 0, 0.1); z-index: -3; }
畫出腿的外側:
.leg::before { content: ''; position: absolute; width: 2.5em; height: inherit; background-color: white; border-bottom-left-radius: 100%; left: -2.5em; box-shadow: inset 0.7em 1.5em 0.7em rgba(0, 0, 0, 0.4); }
至此,完成了右腿。將右腿複製並水平翻轉,即可得到左腿:
.leg.left { transform-origin: right; transform: scaleX(-1); }
大功告成!
#以上是如何使用純CSS實現大白的形象(附源碼)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

當他們在2013年去Chrome時,我們失去了歌劇。與Edge今年早些時候也進行了同樣的交易。邁克·泰勒(Mike Taylor)稱這些變化為“減少

在本週的綜述中,Apple進入Web組件,Instagram如何插入腳本以及一些思考的食物,以進行自託管關鍵資源。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

SublimeText3 Linux新版
SublimeText3 Linux最新版

Dreamweaver CS6
視覺化網頁開發工具

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。