搜尋
首頁web前端css教學如何使用純CSS實現大白的形象(附源碼)

如何使用純CSS實現大白的形象(附源碼)

Oct 08, 2018 pm 04:53 PM
csscss3htmlhtml5前端

這篇文章帶給大家的內容是關於如何使用純CSS實現大白的形象(附源碼),有一定的參考價值,有需要的朋友可以參考一下,希望對你有所幫助。

效果預覽

如何使用純CSS實現大白的形象(附源碼)

原始碼下載

https://github.com/comehop​​e/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中文網其他相關文章!

陳述
本文轉載於:segmentfault思否。如有侵權,請聯絡admin@php.cn刪除
'訂閱播客”鏈接應在哪裡?'訂閱播客”鏈接應在哪裡?Apr 16, 2025 pm 12:04 PM

有一段時間,iTunes是播客中的大狗,因此,如果您將“訂閱播客”鏈接到喜歡:

瀏覽器引擎多樣性瀏覽器引擎多樣性Apr 16, 2025 pm 12:02 PM

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

網絡共享的UX注意事項網絡共享的UX注意事項Apr 16, 2025 am 11:59 AM

從垃圾點擊誘餌網站到大多數出版物的最多,共享按鈕長期以來一直無處不在。然而,這些

每周平台新聞:Apple部署網絡組件,漸進的HTML渲染,自託管關鍵資源每周平台新聞:Apple部署網絡組件,漸進的HTML渲染,自託管關鍵資源Apr 16, 2025 am 11:55 AM

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

git Pathspecs以及如何使用它們git Pathspecs以及如何使用它們Apr 16, 2025 am 11:53 AM

當我查看GIT命令的文檔時,我注意到其中許多人都有選擇。我最初以為這只是一個

產品圖像的彩色拾取器產品圖像的彩色拾取器Apr 16, 2025 am 11:49 AM

聽起來有點像一個困難的問題,不是嗎?我們經常沒有成千上萬種顏色的產品鏡頭,以便我們可以隨身攜帶。我們也不是

黑暗模式與React和Themeprovider切換黑暗模式與React和Themeprovider切換Apr 16, 2025 am 11:46 AM

我喜歡網站具有“暗模式”選項時。黑暗模式使我更容易閱讀網頁,並幫助我的眼睛更放鬆。許多網站,包括

帶有HTML對話框元素的一些動手帶有HTML對話框元素的一些動手Apr 16, 2025 am 11:33 AM

這是我第一次查看HTML元素。我已經意識到了一段時間,但是尚未將其旋轉。它很酷,

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

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

AI Clothes Remover

AI Clothes Remover

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

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
4 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
4 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
4 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.聊天命令以及如何使用它們
4 週前By尊渡假赌尊渡假赌尊渡假赌

熱工具

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器

DVWA

DVWA

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

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

MantisBT

MantisBT

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