這篇文章帶給大家的內容是關於如何使用純CSS實現一隻黑色的憤怒小鳥(附代碼),有一定的參考價值,有需要的朋友可以參考一下,希望對你有所幫助。
#https://github.com/comehope/front-end-daily-challenges
定義dom,容器中包含的元素分別代表
<div> <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-color: turquoise; }
定義容器尺寸和偽元素的共同屬性:
.black-bomb { width: 13em; height: 13em; font-size: 16px; } .black-bomb *::before, .black-bomb *::after { content: ''; position: absolute; }
畫出頭部輪廓:
.black-bomb { position: relative; } .head { position: absolute; width: inherit; height: inherit; background-color: #0f1110; border-radius: 45% 55% 45% 55% / 55% 50% 50% 45%; }
用偽元素畫出眼睛的輪廓:
.eyes::before, .eyes::after { width: 3.4em; height: 3.4em; background-color: #4e4e4e; border-radius: 50%; } .eyes::before { top: 2.7em; left: 21%; } .eyes::after { top: 2.5em; right: 7%; }
用徑向漸變畫出眼球和瞳孔:
.eyes::before, .eyes::after { background-image: radial-gradient( circle at var(--left3) 1.7em, white 0.1em, transparent 0.1em ), radial-gradient( circle at var(--left2) 1.6em, black 0.6em, transparent 0.6em ), radial-gradient( circle at var(--left1) 1.4em, white 1em, transparent 1em ); } .eyes::before { --left1: 2em; --left2: 2.3em; --left3: 2.4em; } .eyes::after { --left1: 1.2em; --left2: 0.9em; --left3: 0.8em; }
用偽元素畫出眉毛:
.eyebrows::before, .eyebrows::after { width: 5.3em; height: 0.8em; background: #cb3c1a; } .eyebrows::before { top: 2.3em; left: 1em; transform: rotate(10deg); } .eyebrows::after { top: 2.2em; right: -0.6em; transform: rotate(-10deg); }
畫出嘴的輪廓:
.mouth { position: absolute; width: 3.6em; height: 3.6em; background-color: #fca90d; top: 4em; left: 6.4em; border-radius: 80% 0 30% 20%; transform: rotate(34deg); border: 0.1em solid black; }
用偽元素畫出上下顎的分界線:
.mouth::before { width: 2.6em; height: 5.7em; border: 0.2em solid; border-radius: 80% 0 0 16%; transform: rotate(35deg); top: -1.1em; left: 1.4em; border-color: transparent transparent transparent black; }
畫出胸前的羽毛:
.head { overflow: hidden; } .head::before { width: inherit; height: inherit; background-color: #474642; border-radius: inherit; top: 76%; left: 12%; }
畫出冠羽:
.hair { position: absolute; width: 1.4em; height: 5em; background-color: #0f1110; top: -3.8em; left: 20%; border-radius: 0 0 40% 40% / 0 0 100% 100%; } .hair::before { width: 80%; height: 1em; background-color: #ffc000; top: 0.3em; left: 10%; }
調整冠羽的形狀:
.hair { transform: rotate(-28deg) skewX(10deg) skewY(-50deg); }
接下來畫陰影,增強立體感。
為頭部增加陰影:
.head { box-shadow: inset -1em 0.5em 1.5em -0.5em rgba(255, 255, 255, 0.3); } .head::after { width: inherit; height: inherit; border-radius: inherit; box-shadow: inset 0.5em -0.5em 0.3em 0.2em rgba(0, 0, 0, 0.2); }
為嘴巴增加陰影:
.mouth { box-shadow: inset 0 0.5em 0.5em rgba(255, 255, 255, 0.3), inset 0.2em -0.5em 1.2em rgba(0, 0, 0, 0.5); }
大功告成!
相關推薦:
如何使用CSS實作貨車loader的效果以上是如何使用純CSS實現一隻黑色的憤怒小鳥(附代碼)的詳細內容。更多資訊請關注PHP中文網其他相關文章!